#include using namespace std; using ll = long long; const int INF = 1e9 + 10; const ll INFL = 4e18; int main() { string S; cin >> S; ll K; cin >> K; int N = S.size(); K--; string ans = ""; for (int i = 0; i < N; i++) { ll cnt = 1; for (int j = i + 1; j < N; j++) { cnt *= S[j] - '0' + 1; } int t = 0; for (int j = 0; j <= S[i] - '0'; j++) { if (cnt * j <= K) { t = j; } } ans += char('0' + t); } while (ans.size() > 1 && ans.front() == '0') { ans.erase(ans.begin()); } cout << ans << endl; }