#include<iostream>
#include<vector>
#include<algorithm>
#include<stdlib.h>
#include<utility>
#include<functional>
#include<cfenv>
#include<cmath>
#include<string>
#include<queue>
#include<map>
#include<set>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define vint vector<ll>
#define vvint vector<vint>
#define P pair<int,int>
#define INT_MAX 2147483647
using namespace std;
typedef long long ll;

ll c(ll n, ll r) {
	ll p1=1, p2=1;
	rep(i, r) {
		p1 *= n - i;
		p2 *= i + 1;
	}
	return p1 / p2;
}

int main(void) {
	string n;
	cin >> n;
	int k; cin >> k;
	int cnt = 1;
	ll sum=0;
	for (int i = 0; i < n.size(); i++) {
		for (int j = 1; j <= n[i] - 48; j++) {
			if (i == n.size() || j == n[i] - 48) {
				continue;
			}
			sum += int(c(n.size()-i - 1, k-1)*pow(9, k-1);
		}
	}

	for (int i =0; i < n.size(); i++) {
		for (int j = 0; j < n[i] - 48; j++) {
			if (j == 0) {
				sum += c(n.size()-i - cnt, k - cnt);
			}
			else {
				sum += c(n.size()-i - cnt - 1, k - cnt - 1);
			}
		}
		if (n[i] - 48 != 0)cnt++;

		if (cnt == k) {
			break;
		}
	}

	return 0;
}