li = [0] * 4 n = int(input()) li[n] = 1 for _ in range(int(input())): p, q = map(int, input().split()) li[p], li[q] = li[q], li[p] print(li.index(1))