#include <bits/stdc++.h>
using namespace std;
int64_t c(int64_t n, int64_t k) {
  int64_t p = 1;
  for (int64_t i = n - k + 1; i <= n; i++) {
    p *= i;
  }
  for (int64_t i = 1; i <= k; i++) {
    p /= i;
  }
  return p;
}
int64_t len(string s) { return s.size(); }
string nine(int64_t N) {
  string s;
  for (int64_t i = 0; i < (N); i++) s += '9';
  return s;
}
string zero(int64_t N) {
  string s;
  for (int64_t i = 0; i < (N); i++) s += '0';
  return s;
}
bool allnine(string s) {
  for (int64_t i = 0; i < (s.size()); i++) {
    if (s[i] != '9') return false;
  }
  return true;
}
int64_t pow(int64_t x, int64_t k) {
  int64_t p = 1;
  for (int64_t i = 0; i < (k); i++) {
    p *= x;
  }
  return p;
}
void dump(string s, string e, int64_t k, int64_t res, int64_t depth) {
  for (int64_t i = 0; i < (depth); i++) {
    cout << " ";
  }
  cout << "s=";
  for (int64_t i = len(s) - 1; i >= 0; i--) {
    cout << s[i];
  }
  cout << " e=";
  for (int64_t i = len(e) - 1; i >= 0; i--) {
    cout << e[i];
  }
  cout << " k=" << k << " res=" << res << endl;
}
string cutmsb(string s) {
  int64_t n = s.size();
  string res = "";
  bool t = false;
  for (int64_t i = 0; i < (n - 1); i++) {
    if (s[i] != '0' || t) res += s[i];
    if (s[i] != '0') t = true;
  }
  if (len(res) == 0) res = '0';
  return res;
}
int64_t f(string s, string e, int64_t k, int64_t depth) {
  int64_t res = 0;
  int64_t cond;
  if (k == 0) {
    cond = 1;
    res = 1;
  } else if (s == "0" && allnine(e)) {
    cond = 2;
    res = c(len(e), k) * pow(9, k);
  } else {
    cond = 3;
    int64_t n = len(e);
    for (char c = '0'; c <= e[n - 1]; c++) {
      if (c == '0') {
        res += f("0", nine(n - 1), k, depth + 1);
      } else if (c == e[n - 1]) {
        res += f("0", cutmsb(e), k - 1, depth + 1);
      } else {
        res += f("0", nine(n - 1), k - 1, depth + 1);
      }
    }
  }
  return res;
}
signed main() {
  int64_t K;
  string s;
  cin >> s >> K;
  reverse(begin(s), end(s));
  cout << f("0", s, K, 0) << endl;
  return 0;
}
