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