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