n=int(input()) m=int(input()) a=[0]*4 a[n]=1 for i in range(m): b,c=map(int,input().split()) a[b],a[c]=a[c],a[b] print(a.index(1))