N = int(input()) M = int(input()) cup = [False] * 4 cup[N] = True for _ in range(M): a, b = map(int, input().split()) cup[a], cup[b] = cup[b], cup[a] print(cup.index(True))