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