ball = 1 for i in range(5): j = int(input()) k = int(input()) if j == ball: ball = k elif k == ball: ball = j print(ball)