#include <bits/stdc++.h>
using namespace std;
long long combi(int n, int k) {
  long long answer = 1;
  for (long long i = n; i > n - k; i--) {
    answer *= i;
  }
  for (long long i = 2; i <= k; i++) {
    answer /= i;
  }
  return answer;
}
long long jou(int n, int k) {
  long long answer = 1;
  for (int i = 0; i < k; i++) {
    answer *= n;
  }
  return answer;
}
int main() {
  string n;
  int k;
  long long answer = 0;
  cin >> n >> k;
  int keta = n.length() - 1;
  if (keta + 1 < k) {
    cout << 0 << endl;
    return 0;
  } else if (k < keta + 1) {
    answer += combi(keta, k) * jou(9, k);
  }
  k--;
  if (k <= 0) {
    cout << answer + atoi(n.substr(0, 1).c_str()) << endl;
    return 0;
  }
  for (int i = 1; i < atoi(n.substr(0, 1).c_str()); i++) {
    answer += combi(keta, k) * jou(9, k);
  }
  n = n.substr(1, n.length() - 1);
  k--;
  keta--;
  if (k <= 0) {
    if (keta >= 2) {
      answer += combi(keta, 1) * jou(9, 1);
    }
    cout << answer + atoi(n.substr(0, 1).c_str()) << endl;
    return 0;
  }
  for (int i = 1; i < atoi(n.substr(0, 1).c_str()); i++) {
    answer += combi(keta, k) * jou(9, k);
  }
  n = n.substr(1, n.length() - 1);
  keta--;
  if (keta >= 2) {
    answer += combi(keta - 2, 1) * jou(9, 1);
  }
  cout << answer + atoi(n.substr(0, 1).c_str()) << endl;
  return 0;
}
