Router

Simulate a buffer of size N: packets arrive in order, 0 means one is handled and removed from the front, and a packet arriving with the buffer full is dropped.

Easy3QueueSimulationImplementationArrayInterviewNo attempts yetTime limit1sMemory limit512 MB

Problem

Computers connected to the internet exchange information in units called packets. Computers are not linked one by one, so a packet usually passes through several routers before it reaches its destination. A router is like a parcel hub: it receives a packet and forwards it to the next router or, when the destination is directly connected, to that destination.

Inside a router there is a buffer that holds arriving packets for a short time. Packets wait in the buffer in arrival order, and the router handles them one by one from the front and removes each handled packet from the buffer. When packets arrive faster than the router handles them, the buffer fills up. A packet that arrives while the buffer is full is discarded, and every arrival keeps being discarded until free space appears.

Assume there is only one router. Given the record of arrivals and handling steps, write a program that reports the packets left in the buffer. Do not consider how a packet is handled in detail or where it is sent.

Input

The first line holds a natural number NN, the size of the buffer.

From the second line, each line holds one event in chronological order. A positive integer means the packet with that number arrived, 00 means the router handled one packet, and 1-1 marks the end of input. 00 never appears while the buffer is empty.

Output

Print the packets left in the buffer from front to back, separated by spaces. If the buffer is empty, print empty.