n = int(input()) m = int(input()) l = [False] * 3 l[n - 1] = True for i in range(m): a, b = map(lambda x: int(x) - 1, input().split()) l[a],l[b] = l[b],l[a] print(l.index(True) + 1)