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