ans = [1, 2, 3] n = int(input()) for i in range(int(input())): p, q = map(int, input().split()) ans[p-1], ans[q-1] = ans[q-1], ans[p-1] print(ans.index(n)+1)