You have cups in a line. Only one of these cups will contain a ball, and the ball will be in the . cup from the left. Your friend decides to mess with you, and while you weren't looking they swapped two cups at random, times. However, you had a camera that was able to keep track of all of the switches. Using this, can you determine which cup contains the ball after the switches, counting from left to right?
Input Specification
The first line will contain , the number of swaps that your friend made, and , the cup that contains the ball counting from the left.
The next lines will each contain 2 integers, and , the cups that were swapped by your friend in the specific swap.
Output Specification
One integer, the index of the cup that contains the ball, counting from the left.
Sample Input 1
3 1
1 2
2 3
1 2
Sample Output 1
3
Sample Explanation
The ball starts off in cup . After the first swap, the ball is now in cup . After the second, the ball is now in cup . The third swap does not affect which ball the cup is in, so finally the answer is .
Comments