import math n,b=map(int,input().split()) if n==0 or (b%n==0 and math.gcd(n,b)!=1): print("NaN") exit() i=pow(n,-1,b) print(i)