N = int(input()) M = int(input()) for i in range(M): P, Q = map(int, input().split()) if N == P: N = Q elif N == Q: N = P else: pass print(N)