Problem: After watching a certain anime before going to sleep, Mark dreams of standing in an old classroom with a blackboard that has a sequence of positive integers on it.
Then, professor Koro comes in. He can perform the following operation:
- select an integer that appears at least times on the board,
- erase those appearances, and
- write on the board.
Professor Koro then asks Mark the question, "what is the maximum possible number that could appear on the board after some operations?"
Mark quickly solves this question, but he is still slower than professor Koro. Thus, professor Koro decides to give Mark additional challenges. He will update the initial sequence of integers times. Each time, he will choose positive integers and , then change to . After each update, he will ask Mark the same question again.
Help Mark answer these questions faster than Professor Koro!
Note that the updates are persistent. Changes made to the sequence will apply when processing future updates.
Input Format: The first line of the input contains two integers and (, ) — the length of the sequence and the number of updates, respectively.
The second line contains integers ()
Then, lines follow, each consisting of two integers and (, ), telling to update to .
Output Format: Print lines. The -th line should consist of a single integer — the answer after the -th update.
Note: In the first example test, the program must proceed through updates.
The sequence after the first update is . One sequence of operations that achieves the number the following.
- Initially, the blackboard has numbers .
- Erase two copies of and write , yielding .
- Erase two copies of and write , yielding .
- Erase two copies of and write , yielding .
- Erase two copies of and write , yielding .
Then, in the second update, the array is changed to . This time, Mark cannot achieve . However, one sequence that Mark can use to achieve is shown below.
- Initially, the blackboard has .
- Erase two copies of and write , yielding .
- Erase two copies of and write , yielding .
- Erase two copies of and write , yielding .
In the third update, the array is changed to . One way to achieve is shown below.
- Initially, the blackboard has .
- Erase two copies of and write , yielding .