n = int(input()) m = int(input()) cup = [1, 2, 3] for i in range(m): a, b = map(int, input().split()) a -= 1 b -= 1 cup[a], cup[b] = cup[b], cup[a] print(cup.index(n) + 1)