N = int(input()) M = int(input()) L = [0] * 3 L[N-1] = 1 for _ in range(M): P, Q = map(int, input().split()) L[P-1], L[Q-1] = L[Q-1], L[P-1] print(L)