#include<bits/stdc++.h>
using namespace std;
string s;
int len; 
int n;
int comb(int m, int n){
	//cout << "M:" << m<< " ";
	if(m <= 0 || m < n) return 0;
	int result = 1, d = 1;
	for(int i = 0; i < n; i ++){
		result *= (m - i);
		d *= i+1;
	}
	//cout << result << " " << d << endl;
	if(n == 1)
		return (result/d)*9;
	if(n == 2)
		return result/d*72;
	return result/d*9*8*7;
} 
int main(){
	getline(cin,s);
	cin >> n;
	
	len = s.size();
	if(n == 1)
		cout << s[0]-48 + comb(len-1, 1);
	if(n == 2)
		cout << (s[0]-48-1) * comb(len-1, 1) + (s[1]-48) + comb(len-1, 2);
	if(n == 3)
		cout << (s[0]-48-1) * comb(len-1, 2) + (s[1]-48-1)*comb(len-2,1) + (s[2]-48) + comb(len-3, 1) + comb(len-1,3));
	
	return 0;
} 