from math import gcd n,b=map(int,input().split()) g=gcd(n,b) if g!=1: exit(print('NaN')) ans=pow(n,b-2,b) print(ans)