N = int(input()) M = int(input()) for _ in range(M): x, y = map(int, input().split()) if x == N: N = y elif y == N: N = x print(N)