n=int(input()) m=int(input()) c=[0]*3 c[n-1]=1 for i in range(m): a,b=map(int,input().split()) a-=1 b-=1 c[a],c[b]=c[b],c[a] print(c.index(1)+1)