N = int(input()) M = int(input()) lsPQ = [map(int,input().split()) for i in range(M)] ls = ['x']*4 ls[N] = 'o' for i in range(M): p,q = lsPQ[i] ls[p],ls[q] = ls[q],ls[p] print(ls.index('o'))