#K4196. Elevator Simulation

    ID: 26981 Type: Default 1000ms 256MiB

Elevator Simulation

Elevator Simulation

You are given a building with F floors, numbered from 1 to F. The elevator starts at floor 1. You are given N requests in the form of floor numbers.

For each request, if the requested floor is within the range [1, F], the elevator moves to that floor and the floor is recorded in the sequence of visited floors. If a request is outside the valid range, the elevator ignores it and does not move.

Your task is to simulate the elevator movement and output the sequence of floors visited. The output should start with the initial floor 1, followed by the floors the elevator stops at as a result of valid requests.

Note: The input is provided through standard input (stdin) and the output should be printed to standard output (stdout).

In mathematical form, if we define the sequence of visited floors as \(V\) and the list of requests as \(R = [r_1, r_2, \dots, r_N]\), then:

\[ V_0 = 1 \quad \text{and} \quad V_i = \begin{cases} r_i & \text{if } 1 \le r_i \le F, \\ \text{(no change)} & \text{otherwise.} \end{cases} \]

inputFormat

The first line of the input contains two integers F and N separated by a space, where F is the number of floors and N is the number of requests.

If N > 0, the second line contains N integers separated by spaces representing the requested floors. If N is zero, the second line may be omitted.

outputFormat

Output the sequence of floors visited by the elevator as space-separated integers on a single line. The sequence always starts with 1.

## sample
5 7
2 3 5 4 1 4 2
1 2 3 5 4 1 4 2