n = int(input()) m = int(input()) for i in range(m): P = list(map(int, input().split())) if P[0] == n:n = P[1] elif P[1] == n:n = P[0] print(n)