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