N = int(input()) N -= 1 M = int(input()) cup = [0, 0, 0] cup[N] = 1 for i in range(M): f, t = map(int, input().split()) f -= 1 t -= 1 cup[t], cup[f] = cup[f], cup[t] print(cup.index(1) + 1)