#abc299b. [abc299_b]Trick Taking
[abc299_b]Trick Taking
Problem Statement
players with ID numbers 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 , the card played by player has a color and a rank . All of are different.
Among the players, one winner is decided as follows.
- If one or more cards with the color 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 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 is the winner. (Note that player may win.)
Print the ID number of the winner.
Constraints
- All values in the input are integers.
Input
The input is given from Standard Input in the following format:
Output
Print the answer.
Sample Input 1
4 2
1 2 1 2
6 3 4 5
Sample Output 1
4
Cards with the color are played. Thus, the winner is player , who has played the card with the greatest rank, , among those cards.
Sample Input 2
4 2
1 3 1 4
6 3 4 5
Sample Output 2
1
No card with the color is played. Thus, the winner is player , who has played the card with the greatest rank, , among the cards with the color of the card played by player (color ).
Sample Input 3
2 1000000000
1000000000 1
1 1000000000
Sample Output 3
1