L = [0, 0, 0, 0] L[int(input())] = 1 for i in range(int(input())): P, Q = map(int, input().split()) L[P], L[Q] = L[Q], L[P] print(L.index(1))