N=int(input()) M=int(input()) ANS=N for i in range(M): x,y=map(int,input().split()) if ANS==x: ANS=y elif ANS==y: ANS=x print(ANS)