c = int(input()); M = int(input()) for i in range(M): p,q = [int(e) for e in input().split()] if p==c: c==q elif q==c: c==p print(c)