atcoder#ABC299B. [ABC299B] Trick Taking
[ABC299B] Trick Taking
Score : points
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.
4 2
1 2 1 2
6 3 4 5
4
Cards with the color are played. Thus, the winner is player , who has played the card with the greatest rank, , among those cards.
4 2
1 3 1 4
6 3 4 5
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 ).
2 1000000000
1000000000 1
1 1000000000
1