ans = 1 for _ in range(int(input())) : a, b = map(int, input().split()) ans = a if b == ans else b if a == ans else ans print(ans)