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