#include <bits/stdc++.h>
using namespace std;
string n;
long long k, result;
map<pair<string, int>, int> save;
long long C(long long, long long);
long long solve(string, long long);
int main() {
  save.clear();
  cin >> n >> k;
  result = solve(n, k);
  cout << result << "\n";
}
long long C(long long a, long long b) {
  if (a == b) return 1;
  if (b == 1) return a;
  return C(a - 1, b) + C(a - 1, b - 1);
}
long long solve(string a, long long b) {
  if (save.find({a, b}) != save.end()) return save[{a, b}];
  if (a.length() < b) return 0;
  long long ans = 0;
  if (b == 1)
    ans = 9 * (a.length() - 1) + a[0] - '0';
  else {
    string tmp = "";
    for (int i = 0; i < a.length() - 1; ++i) tmp += '9';
    ans += solve(tmp, b);
    ans += solve(tmp, b - 1) * (a[0] - '1');
    ans += solve(a.substr(1, a.length() - 1), b - 1);
  }
  return save[{a, b}] = ans;
}
