Nikita has a stack. A stack in this problem is a data structure that supports two operations. Operation push(x) puts an integer x on the top of the stack, and operation pop() deletes the top integer from the stack, i.e. the last added. If the stack is empty, then the operation pop() does nothing.
Nikita made m operations with the stack but forgot them. Now Nikita wants to remember them. He remembers them one by one, on the i-th step he remembers an operation he made pi-th. In other words, he remembers the operations in order of some permutation p1,p2,...,pm. After each step Nikita wants to know what is the integer on the top of the stack after performing the operations he have already remembered, in the corresponding order. Help him!
Output
Print
m integers. The integer
i should equal the number on the top of the stack after performing all the operations Nikita remembered on the steps from
1 to
i. If the stack is empty after performing all these operations, print
-1.
Note
In the first example, after Nikita remembers the operation on the first step, the operation
push(2) is the only operation, so the answer is
2. After he remembers the operation
pop() which was done before
push(2), answer stays the same.
In the second example, the operations are
push(2),
push(3) and
pop(). Nikita remembers them in the order they were performed.
In the third example Nikita remembers the operations in the reversed order.