cap = int(input()) n = int(input()) for i in range(n): p,q = map(int,input().split(" ")) if p == cap: cap = q elif q == cap: cap = p print(cap)