You are considering a permutation
To make this more interesting, the permutation will be updated. You are given u v
meaning that
Note that the indices are 1-indexed, but the values are from
Constraints
For all
Subtask 1 [20%]
Subtask 2 [30%]
Subtask 3 [30%]
Subtask 4 [20%]
Input Specification
The first line will contain two space-separated integers,
The next line will contain
The following
Output Specification
For each query, output a line containing a single non-negative integer, the smallest possible
Sample Input 1
4 2
2 3 1 0
4 3
1 1
Sample Output 1
2
2
Explanation for Sample 1
After the first update, the permutation is
The second update doesn't change anything.
Sample Input 2
4 3
1 0 2 3
1 2
3 4
1 4
Sample Output 2
0
1
2
Comments