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