n,m=int(input()),int(input()) b=['T' if i==(n-1) else 'F' for i in range(3)] for j in range(m): x,y=map(int,input().split()) x-=1 y-=1 b[x],b[y]=b[y],b[x] print(b.index('T')+1)