#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define MAX 100000
#define INF 2140000000
#define MOD 1000000007

long long choose(int l, int k) {
	if (k > l) {
		return 0;
	}

	if (k == 0) {
		return 1;
	}
	else if (k == 1) {
		return l;
	}
	else if(k == 2) {
		return (l * (l - 1)) / 2;
	}
	else {
		return (l * (l - 1) * (l - 2)) / 6;
	}
}
int main() {
	string n;
	cin >> n;
	int k;
	cin >> k;

	if (k > (int) n.size()) {
		cout << 0 << endl;
		return;
	}

	int l = (int) n.size() - 1;

	long long ans1 = choose(l,k) * pow(9,k), ans2 = (n[0] - '0' - 1) * choose(l, k - 1) * pow(9, k - 1);
	k--;

	if (k == 0) {
		ans2++;	
	}
	else if (k == 1) {
		int ind = -1;
		for (int i = 1; i < (int) n.size(); ++i) {
			if (n[i] != '0') {
				ind = i;
				break;
			}
		}

		if (ind != -1) {
			ans2 += (n[ind] - '0') + ((int) n.size() - 1 - ind) * 9;
		}
	}
	else {
		int ind = -1;
		for (int i = 1; i < (int) n.size(); ++i) {
			if (n[i] != '0') {
				ind = i;
				break;
			}
		}

		if (ind < (int) n.size() - 1) {
			ans2 += choose((int) n.size() - 1 - ind, 2) * 9 * 9;
			ans2 += (n[ind] - '0' - 1) * choose((int) n.size() - 1 - ind, 1) * 9;

			int kk = ind;
			for (int i = kk + 1; i < (int) n.size(); ++i) {
				if (n[i] != '0') {
					ind = i;
					break;
				}
			}

			if (ind != -1) {
				ans2 += (n[ind] - '0') + ((int) n.size() - 1 - ind) * 9;
			}		
		}

	}

	cout << ans1 + ans2 << endl;

	return 0;
}