N, M = int(input()), int(input()) pq = tuple(tuple(int(s) for s in input().split()) for i in range(M)) for p, q in pq: if p == N: N = q elif q == N: N = p print(N)