N = int(input()) M = int(input()) L = [0] * 4 L[N] = 1 for _ in range(M): P, Q = map(int, input().split()) L[P], L[Q] = L[Q], L[P] print(L.index(1))