N = int(input()) N -= 1 K = [False] * 3 K[N] = True M = int(input()) for _ in range(M): P,Q = map(int,input().split()) P -= 1 Q -= 1 K[P],K[Q] = K[Q],K[P] for i in range(3): if K[i]: print(i+1) break