#include <iostream>
#include <string>

long long count2(long long first, long long second, long long size) {
	return (size - 1) * (size - 2) / 2 * 81 + (first - 1) * (size - 1) * 9 + (size - 2) * 9 + second;
}

long long count3(long long first, long long second, long long third, long long size) {
	return (size - 1) * (size - 2) * (size - 3) / 6 * 729 + (first - 1) * count2(9, 9, size - 1) + count2(second, third, size - 1);
}

long long main() {
	std::string n;
	std::cin >> n;
	
	long long k;
	std::cin >> k;
	
	if(k > n.size()){
		std::cout << 0 << std::endl;
		return 0;
	}
	
	if(k == 1){
		std::cout << 9*(n.size() - 1) + n[0] - '0' << std::endl;
		return 0;
	}
	if(k == 2){
		std::cout << count2(n[0] - '0', n[1] - '0', n.size()) << std::endl;
		return 0;
	}
	if(k == 3){
		std::cout << count3(n[0] - '0', n[1] - '0', n[2] - '0', n.size()) << std::endl;
		return 0;
	}
}