//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
const int dx[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
const int dy[8] = { 1, 1, 1, 0, 0, -1, -1, -1 };
const int lr[4] = { 0, 1, 0, -1 };
const int ud[4] = { 1, 0, -1, 0 };



//LOVE Ayane Sakura



using namespace std;



int main() {
	string N;
	int K;
	cin >> N >> K;
	long long ans = 0;
	if (K == 1) {
		for (int i = 0; i < N.size(); ++i) {
			if (i == 0) {
				ans += (int)N[i] - '0';
			}
			else {
				ans += 9;
			}
		}
	}
	else if (K == 2) {
		for (int i = 1; i < N.size(); ++i) {
			ans += ((int)N[0] - '0' - 1) * 9;
			ans += 1 * ((int)N[i] - '0');
		}
		for (int i = 1; i < N.size(); ++i) {
			for (int j = i + 1; j < N.size(); ++j) {
				ans += 9 * 9;
			}
		}
	}
	else if (K == 3) {
		for (int i = 1; i < N.size(); ++i) {
			for (int j = i + 1; j < N.size(); ++j) {
				ans += ((int)N[0] - '0' - 1) * 9 * 9;
				ans += 1 * ((int)N[i] - '0') * ((int)N[j] - '0');
			}
		}
		for (int i = 1; i < N.size(); ++i) {
			for (int j = i + 1; j < N.size(); ++j) {
				for (int k = j + 1; k < N.size(); ++k) {
					ans += 9 * 9 * 9;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}
