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