#K72662. Optimal Elevator Stops
Optimal Elevator Stops
Optimal Elevator Stops
You are given the number of floors in a building, F, and a list of elevator requests. Each request is represented by a pair of integers indicating the starting floor and the destination floor. Your task is to determine the set of floors at which the elevator should stop. The result should include every floor that appears in any request, output in ascending order.
Note: Although the total number of floors is provided, you only need to consider the floors that are explicitly mentioned in the requests.
The formula to represent this set is given by:
$$S = \{ x \mid x \text{ appears in any request pair } (a, b) \} $$and the answer is the sorted sequence of all elements in \( S \).
inputFormat
The first line of input contains an integer F representing the total number of floors in the building.
The second line contains an integer N representing the number of elevator requests.
Each of the next N lines contains two integers separated by a space: the starting floor and the destination floor of a request.
outputFormat
Output a single line containing the unique floors at which the elevator should stop, arranged in ascending order. The floors should be separated by a single space.
## sample5
3
0 3
3 4
2 1
0 1 2 3 4