N = int(input()) cup = [False] * 3 cup[N - 1] = True 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] for i in range(3): if cup[i]: print(i + 1) break