#include <bits/stdc++.h>
using namespace std;
int kaijou(int n) {
  if (n == 1)
    return 1;
  else
    return n * kaijou(n - 1);
}
int combination(int n, int m) {
  int tmp1, tmp2, tmp3;
  tmp1 = kaijou(n);
  tmp2 = kaijou(n - m);
  tmp3 = kaijou(m);
  return tmp1 / tmp2 / tmp3;
}
int main() {
  string N;
  cin >> N;
  int K;
  cin >> K;
  if (K > N.size()) {
    cout << "0" << endl;
    return 0;
  }
  long ans = 0;
  if (K == 1) {
    ans = 9 * (N.size() - 1);
    ans += (N[0] - '0');
    cout << ans << endl;
    return 0;
  } else if (K == 2) {
    for (int i = K - 1; i < N.size() - 1; i++) {
      ans += 9 * i * 9;
    }
    ans += (N[0] - '0' - 1) * (9 * (N.size() - 1));
    for (int i = 1; i < N.size(); i++) {
      ans += (N[i] - '0');
    }
    cout << ans << endl;
    return 0;
  } else if (K == 3) {
    ans += (N[0] - '0' - 1) * combination(N.size() - 1, 2) * 81;
    for (int i = 1; i < N.size(); i++) {
      ans += (N[i] - '0');
    }
    cout << ans << endl;
    return 0;
  }
}
