#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; 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; 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; } cout << r << endl; return 0; }