N = int(input()) M = int(input()) for i in range(0, M, 1): a, b = map(int, input().split()) if N == a: N = b elif N == b: N = a print(N)