# No.26 シャッフルゲーム N, M = [int(input()) for i in range(2)] cup = [0, 0, 0] cup[N - 1] = 1 for i in range(M): s = [int(i) for i in input().split()] tmp = cup[s[0] - 1] cup[s[0] - 1] = cup[s[1] - 1] cup[s[1] - 1] = tmp for i in range(3): if cup[i] == 1: print(i + 1) break