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