N = int(input()) M = int(input()) log = [list(map(int,input().split())) for i in range(M)] for i in log: if i[0] == N: N = i[1] elif i[1] == N: N = i[0] print(N)