import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N = int(readline()) M = int(readline()) m = map(int,read().split()) PQ = zip(m,m) for p,q in PQ: if p == N: N = q elif q == N: N = p print(N)