#include<iostream>
using namespace std;
#include <vector>  
#include<algorithm>
#include<string>

int main()
{
	string N;
	long K;
	long long  result=0;

	

	cin >> N >> K;


	while (true) {

		int NLen = N.length();

		//0ホニャララ
		long i = 1;
		for (int a = 0; a < K; a++) {
			i *= (NLen - 1 - a);
		}
		result += i * 9;

		//Xホニャララ(X<一番上の桁)
		string firstString = N.substr(0, 1);
		int top = atoi(firstString.c_str());
		i = 1;
		for (int a = 0; a < K - 1; a++) {
			i *= (NLen - 1 - a);
		}
		i *= (top - 1);
		result += pow( 9,i);

		//Xホニャララ(Xが一番上の桁)
		if (K == 1) {
			result += 1;


			break;
		}
		else {
			K-=1;
			N = N.substr(1);
		}

	}

	
	
	cout << result<< endl;
}

