n=input() m=input() c=[0]*3 c[n-1]=1 for _ in[0]*m: p,q=map(int,raw_input().split()) c[p-1],c[q-1]=c[q-1],c[p-1] print c.index(1)+1