#ABC170E. [ABC170E] Smart Infants

[ABC170E] Smart Infants

Score : 500500 points

Problem Statement

There are NN infants registered in AtCoder, numbered 11 to NN, and 2×1052\times 10^5 kindergartens, numbered 11 to 2×1052\times 10^5. Infant ii has a rating of AiA_i and initially belongs to Kindergarten BiB_i.

From now on, QQ transfers will happen. After the jj-th transfer, Infant CjC_j will belong to Kindergarten DjD_j.

Here, we define the evenness as follows. For each kindergarten with one or more infants registered in AtCoder, let us find the highest rating of an infant in the kindergarten. The evenness is then defined as the lowest among those ratings.

For each of the QQ transfers, find the evenness just after the transfer.

Constraints

  • 1N,Q2×1051 \leq N,Q \leq 2 \times 10^5
  • 1Ai1091 \leq A_i \leq 10^9
  • 1CjN1 \leq C_j \leq N
  • 1Bi,Dj2×1051 \leq B_i,D_j \leq 2 \times 10^5
  • All values in input are integers.
  • In the jj-th transfer, Infant CjC_j changes the kindergarten it belongs to.

Input

Input is given from Standard Input in the following format:

NN QQ

A1A_1 B1B_1

A2A_2 B2B_2

::

ANA_N BNB_N

C1C_1 D1D_1

C2C_2 D2D_2

::

CQC_Q DQD_Q

Output

Print QQ lines. The jj-th line should contain the evenness just after the jj-th transfer.

6 3
8 1
6 2
9 3
1 1
2 2
1 3
4 3
2 1
1 2
6
2
6

Initially, Infant 1,41, 4 belongs to Kindergarten 11, Infant 2,52, 5 belongs to Kindergarten 22, and Infant 3,63, 6 belongs to Kindergarten 33.

After the 11-st transfer that makes Infant 44 belong to Kindergarten 33, Infant 11 belongs to Kindergarten 11, Infant 2,52, 5 belong to Kindergarten 22, and Infant 3,4,63, 4, 6 belong to Kindergarten 33. The highest ratings of an infant in Kindergarten 1,2,31, 2, 3 are 8,6,98, 6, 9, respectively. The lowest among them is 66, so the 11-st line in the output should contain 66.

After the 22-nd transfer that makes Infant 22 belong to Kindergarten 11, Infant 1,21, 2 belong to Kindergarten 11, Infant 55 belongs to Kindergarten 22, and Infant 3,4,63, 4, 6 belong to Kindergarten 33. The highest ratings of an infant in Kindergarten 1,2,31, 2, 3 are 8,2,98, 2, 9, respectively. The lowest among them is 22, so the 22-nd line in the output should contain 22.

After the 33-rd transfer that makes Infant 11 belong to Kindergarten 22, Infant 22 belongs to Kindergarten 11, Infant 1,51, 5 belong to Kindergarten 22, and Infant 3,4,63, 4, 6 belong to Kindergarten 33. The highest ratings of an infant in Kindergarten 1,2,31, 2, 3 are 6,8,96, 8, 9, respectively. The lowest among them is 66, so the 33-rd line in the output should contain 66.

2 2
4208 1234
3056 5678
1 2020
2 2020
3056
4208