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