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