import sys
N = int(input())
E = int(input())
offset = 1 << 29
if N >= 0 and round(N ** 0.5) ** 2 == N:
	print(round(N ** 0.5))
	sys.exit()
cand = set([0])
key = 1
for i in range(E):
	n_cand = set()
	for i in range(5):
		for j in cand:
			if ((j + i * key) ** 2 - N) % (key * 5) == 0:
				n_cand.add(j + i * key)
	cand = n_cand
	key *= 5
for i in cand:
	if (i + offset) % key - offset <= offset:
		print((i + offset) % key - offset)
		sys.exit()
print("NaN")