from math import gcd n,b = map(int,input().split()) if(gcd(n,b) == 1): print(pow(n,-1,b)) else: print("NaN")