def solve(N, V): return "NaN" N = int(input()) M = int(input()) V = [] for _ in range(M): b, c = map(int, input().split()) c %= b V.append((c, b)) print(solve(N, V))