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