N = int(input()) M = int(input()) for m in range(M): p, q = map(int, input().split()) if p == N: N = q elif q == N: N = p print(N)