s = [False] * 4 s[int(input())] = True for i in range(int(input())): a, b = map(int, input().split()) s[a], s[b] = s[b], s[a] for i in range(4): if s[i]: print(i)