N = int(input()) M = int(input()) L = [1, 2, 3] for _ in range(M): p, q = map(int, input().split()) L[p-1], L[q-1] = L[q-1], L[p-1] print(L.index(N)+1)