n = int(input()) m = int(input()) l = [0] * 3 for i in range(m): l[n-1] = 1 p, q = map(int, input().split()) if p == n: l[q-1] = 1 l[p-1] = 0 elif q == n: l[p-1] = 1 l[q-1] = 0 print(l.index(1) + 1)