#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#include<stdio.h>

using ll = long long;

using namespace std;

ll mod = 1000000007;

ll n_pow(ll a, ll n) {
	if (n == 0)return 1;
	ll t = n_pow(a, n / 2);
	t *= t;
	t %= x;
	if (n % 2 == 1)t *= a;
	return t % x;
}

const int INF = 1001001001;

ll k_1(string s) {
	ll ans = (s.size() - 1) * 9;
	int p = s[0] - '0';
	ans += p;
	return ans;
}

ll k_2(string s) {
	ll n = s.size();
	ll ans = 81 * (n - 1)*(n - 2) / 2;
	int p = s[0] - '0';
	ans += (p - 1)*(n - 1) * 9;
	ans += k_1(s.substr(1));
	return ans;
}

ll k_3(string s) {
	ll n = s.size();
	ll ans = 729 * (n - 1)*(n - 2)*(n - 3) / 6;
	ll p = s[0] - '0';
	ans += (p - 1) * 81 * (n - 1)*(n - 2) / 2;
	ans += k_2(s.substr(1));
	return ans;
}

int main() {
	string s;
	cin >> s;
	ll n = s.size();
	int k;
	cin >> k;
	ll ans;
	if (k == 1) {
		ans = k_1(s);
	}
	else if (k == 2) {
		ans = k_2(s);
	}
	else {
		ans = k_3(s);
	}
	cout << ans << endl;
	return 0;
}