Time Limit : sec, Memory Limit : KB
English / Japanese  

Gas Station

 

The gas station at the White Tiger Service Area has $N$ lanes, numbered from 1 to $N$. The first car in each lane is allowed to refuel.

When a car enters the gas station, it chooses the lane with the fewest cars in line and lines up at the end of the queue. If there is more than one such lane, they choose the lane with the lowest number. When the car has finished refueling, it will leave the lane and the car behind it will refuel. Once you have chosen a lane, you cannot move to another lane. Also, the order of the cars in the lane will not change.

Given the number of lanes, the cars that have entered, and the lanes that have finished refueling, write a program that outputs the numbers of the cars that have finished refueling in order. The entry information is given as the number of the car entering the stand, and the refueling end information is given as the lane number where the first car has finished refueling. It is assumed that no cars are lined up in any lane at the beginning.

Input

The input is given in the following form.

$N$ $M$
$info_1$
$info_2$
:
$info_M$

In the first line, the number of lanes $N$ ($1 \leq N \leq 10$), and the number of information $M$ ($2 \leq M \leq 10,000$) are given. In the following $M$ lines, each information $info_i$ is given. Each $info_i$ is given in one of the following formats.

0 $lane$

or

1 $car$

If the first number is 0, it means that the first car in the lane whose number is $lane$ ($1 \leq lane \leq N$) has finished refueling. If the first number is 1, it indicates that the car whose number is $car$ ($1 \leq car \leq 9,999$) has entered the stand.

The input satisfies the following constraints.

  • The numbers of all cars entering the gas station are different.
  • There is always at least one piece of information where the first number is 0 or 1, respectively.
  • For a lane with no cars, no information whose first number is 0 will be given.

Output

For each refueling end information, output the number of the car that has finished refueling in a line.  

Sample Input and Output

Sample Input

2 7
1 999
1 1000
0 2
1 1001
1 1002
0 1
0 1

Sample Output

1000
999
1002