#include int main () { long long n = 0LL; int e = 0; int res = 0; long long ans = -1LL; long long d = 1LL; long long tmp = 0LL; long long g[25][25] = {}; int gcnt[25] = {}; res = scanf("%lld", &n); res = scanf("%d", &e); while (e > 0) { d *= 5LL; e--; } if (n > 0LL) { n %= d; } else { n = (d-(-n)%d)%d; } for (int i = 0; i < 25; i++) { g[(i*i)%25][gcnt[(i*i)%25]] = (long long)i; gcnt[(i*i)%25]++; } while (ans < 0LL && tmp < d && tmp <= (1LL<<29LL)) { for (int i = 0; i < gcnt[(int)(n%25LL)]; i++) { long long tmp2 = tmp+g[(int)(n%25LL)][i]; if ((tmp2*tmp2)%d == n) { ans = tmp2; } } tmp += 25LL; } if (ans < 0LL) { printf("NaN\n"); } else { printf("%lld\n", ans); } return 0; }