n = int(input()) e = int(input()) if e == 0 or n == 0: print(0) exit() if (n % (5 ** e) == 0): print(0) exit() ee = e nn = n basis = 1 while n % 25 == 0: n //= 25 e -= 2 basis *= 5 if not (n % 5 == 1 or n % 5 == 4): print("NaN") exit() a = -1 for i in range(5): if (i * i - n) % 5 == 0: a = i break assert a >= 0 for t in range(2, e+1): c = (a * a - n) // (5 ** (t-1)) y = -1 for yy in range(5): if (2 * a * yy + c) % 5 == 0: y = yy break assert y >= 0 b = (a + 5 ** (t-1) * y) % (5 ** t) a = b a *= basis a %= (5 ** ee) if a > 2 ** 29: a -= 5 ** ee if a < -2 ** 29: print("NaN") exit() print(a) #print((a * a - nn) % (5 ** ee) == 0)