#include <bits/stdc++.h>
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;
		}
	}
	stack<int> 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();
	}
	cout<< endl;
}