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