n=int(input()) m=int(input()) l=[list(map(int,input().split())) for i in range(m)] for i in range(m): if n==l[i][0]: n=l[i][1] elif n==l[i][1]: n=l[i][0] print(n)