#include using namespace std; using ll = long long; int main () { ll N, K; cin >> N >> K; ll X = 1; { string s = to_string(N); for (auto& a : s) { X *= (a - '0') + 1ll; } } K --; if (!K) { puts("0"); return 0; } stack st; while (K) { ll w = ((N % 10) + 1); st.push(K % w); K /= w; X /= ((N % 10) + 1); N /= 10; } while (!st.empty()) { cout << st.top(); st.pop(); } cout<< endl; }