N = int(input()) M = int(input()) sw = [list(map(int, input().split())) for _ in range(M)] pos = list(range(1, 4)) for p, q in sw: pos[p - 1], pos[q - 1] = pos[q - 1], pos[p - 1] print(pos.index(N) + 1)