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