A=[0]*4 A[int(input())]=1 for _ in '1'*int(input()): P,Q=map(int,input().split()) A[P],A[Q]=A[Q],A[P] print(A.index(1))