Rearranging a Sequence

Given the sequence 1 to n, each request moves a named integer to the front while keeping the rest in order; output the final sequence.

Medium4Linked listImplementationSimulationInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

You are given the integers 11 through nn in order, forming the sequence (1,2,3,,n)(1, 2, 3, \ldots, n). A number of requests follow. Each request names one integer in the sequence, and that integer moves to the head of the sequence. The order of the remaining elements stays the same. Report the order of the elements after all requests are processed in the given order.

Input

The input is a single test case in the following form.

n m
e1
.
.
.
em

The integer nn is the length of the sequence (1n2000001 \le n \le 200000). The integer mm is the number of requests (1m1000001 \le m \le 100000). The next mm lines hold the requests e1,,eme_1, \ldots, e_m, one per line. Each request eie_i (1im1 \le i \le m) is an integer between 11 and nn inclusive and designates the element to move. A request names the integer itself, not its position in the sequence.

Output

Print the sequence after all requests are processed. Print its elements one per line, in the order in which they appear in the sequence.

Hint

Take n=5n = 5 with the requests 44, 22, 55 in that order. The initial sequence is (1,2,3,4,5)(1, 2, 3, 4, 5). The first request moves the integer 44 to the head, giving (4,1,2,3,5)(4, 1, 2, 3, 5). The next request moves 22 to the head, giving (2,4,1,3,5)(2, 4, 1, 3, 5). The last request moves 55, giving (5,2,4,1,3)(5, 2, 4, 1, 3).