N, B = map(int, input().split()) for i in range(B): if (i*N-1)%B == 0: print(i) exit() print("NaN")