a = [0] * 4 a[int(input())] = 1 for __ in range(int(input())): i, j = map(int, input().split()) a[i], a[j] = a[j], a[i] print(a.index(1))