A=[0]*3 N,M=map(int,(input(),input())) A[N-1]=1 for _ in '1'*M: P,Q=[int(x)-1 for x in input().split()] A[P],A[Q]=A[Q],A[P] print(A.index(1)+1)