#include using namespace std; typedef long long ll; // typedef unsigned long long ull; // const ll INF = numeric_limits::max() / 4; // const int INF = numeric_limits::max() / 4; // cout << std::fixed << std::setprecision(15); int main() { ll N; int E; cin >> N >> E; int K = 20; ll EPS = 1; for(int i = 0; i < K; i++) EPS *= 5; if(N < 0) N += EPS; ll D = 0; while(N % 5 == 0){ N /= 5; D++; if(E - D <= 0){ cout << 0 << endl; return 0; } } if(D % 2 == 1){ cout << "NaN" << endl; return 0; } vector T(K, 0); for(int k = 0; k < K; k++){ T[k] = N % 5LL; N /= 5; } vector R(K, 0); vector U(K, 0); for(int e = 0; e < E - D; e++){ ll l = U[e]; U[e] = 0; for(int j = 1; j <= e - 1; j++){ l += R[j] * R[e - j]; } bool f = false; for(R[e] = 0; R[e] < 5; R[e]++){ ll s = R[e] * R[0] * 2; if(e == 0) s = R[0] * R[0]; if((l + s) % 5 == T[e]){ l += s; l /= 5; for(int j = e + 1; j < K; j++){ U[j] += l % 5; l /= 5; } f = true; break; } } if(!f){ cout << "NaN" << endl; return 0; } } ll r = 0; ll d = 1; for(int k = 0; k <= K; k++){ r += R[k] * d; d *= 5LL; } for(int i = 0; i < D / 2; i++) r *= 5; EPS = 1; for(int i = 0; i < E; i++) EPS *= 5; while((1LL << 29) < r) r -= EPS; if(r < -(1LL << 29)){ cout << "NaN" << endl; }else{ cout << r << endl; } return 0; }