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