N, B = map(int, input().split()) try: print(pow(N, -1, B)) except ValueError: print("NaN")