n=int(input()) m=int(input()) data=[[int(s) for s in input().split()] for i in range(m)] ans=[0]*3 ans[n-1]=1 for i in range(m): ans[data[i][0]-1],ans[data[i][1]-1]=ans[data[i][1]-1],ans[data[i][0]-1] print(ans.index(1)+1)