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