n=int(input()) m=int(input()) l=[0,1,2,3] for i in range(m): s,t=map(int,input().split()) a=l[t] b=l[s] l[s]=a l[t]=b print(l.index(1))