atcoder#ABC299B. [ABC299B] Trick Taking

[ABC299B] Trick Taking

Score : 200200 points

Problem Statement

NN players with ID numbers 1,2,,N1, 2, \ldots, N are playing a card game. Each player plays one card.

Each card has two parameters: color and rank, both of which are represented by positive integers. For i=1,2,,Ni = 1, 2, \ldots, N, the card played by player ii has a color CiC_i and a rank RiR_i. All of R1,R2,,RNR_1, R_2, \ldots, R_N are different.

Among the NN players, one winner is decided as follows.

  • If one or more cards with the color TT are played, the player who has played the card with the greatest rank among those cards is the winner.
  • If no card with the color TT is played, the player who has played the card with the greatest rank among the cards with the color of the card played by player 11 is the winner. (Note that player 11 may win.)

Print the ID number of the winner.

Constraints

  • 2N2×1052 \leq N \leq 2 \times 10^5
  • 1T1091 \leq T \leq 10^9
  • 1Ci1091 \leq C_i \leq 10^9
  • 1Ri1091 \leq R_i \leq 10^9
  • ij    RiRji \neq j \implies R_i \neq R_j
  • All values in the input are integers.

Input

The input is given from Standard Input in the following format:

NN TT

C1C_1 C2C_2 \ldots CNC_N

R1R_1 R2R_2 \ldots RNR_N

Output

Print the answer.

4 2
1 2 1 2
6 3 4 5
4

Cards with the color 22 are played. Thus, the winner is player 44, who has played the card with the greatest rank, 55, among those cards.

4 2
1 3 1 4
6 3 4 5
1

No card with the color 22 is played. Thus, the winner is player 11, who has played the card with the greatest rank, 66, among the cards with the color of the card played by player 11 (color 11).

2 1000000000
1000000000 1
1 1000000000
1