n=int(input()) m=int(input()) v=[0,0,0,0] v[n] = 1 for i in range(m): p,q = map(int,input().split()) v[p],v[q] = v[q],v[p] print(v.index(1))