l=[0]*4 l[int(input())]=1 for i in range(int(input())): p,q=map(int,input().split()) l[p],l[q]=l[q],l[p] print(l.index(1))