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