cup=[1,2,3] N=int(input()) # target M=int(input()) # 回数 for _ in range(M): P,Q=map(int,input().split()) cup[P-1],cup[Q-1]=cup[Q-1],cup[P-1] print(cup.index(N)+1)