N, B = map(int, input().split()) A = 0 for i in range(10**6*2): if (A-1)%B == 0: print(i) break A += N else: print("NaN")