#include <bits/stdc++.h>
using namespace std;
const long long INF = pow(10, 9) + 7;
long long kaijou(long long x) {
  if (x == 1 || x == 0) return 1;
  return x * kaijou(x - 1);
};
long long ue(int i, long long k) {
  long long ans = 1;
  for (int ki = 0; ki < (int)(k); ki++) {
    ans *= (long long)i - ki;
  }
  return ans;
};
int main() {
  long long N, K;
  cin >> N >> K;
  string s = to_string(N);
  int keta = s.size();
  long long sum = 0;
  if (keta < K) {
    cout << 0;
    return 0;
  }
  for (int i = K; i < keta; i++) {
    if (i == K) {
      sum += pow(9, K);
      continue;
    }
    sum += pow(9, K) * ue(i - 1, K - 1) / kaijou(K - 1);
  }
  int a = N / (long long)pow(10, keta - 1);
  sum += (a - 1) * pow(9, K - 1) * ue(keta - 1, K - 1) / kaijou(K - 1);
  if (K == 1) sum += 1;
  pair<int, int> se(0, 0), th(0, 0);
  for (int i = 1; i < keta; i++) {
    if (s.at(i) != '0') {
      se.first = s.at(i) - '0';
      se.second = keta - i;
      break;
    }
  }
  for (int i = keta - se.second + 1; i < keta; i++) {
    if (s.at(i) != '0') {
      th.first = s.at(i) - '0';
      th.second = keta - i;
      break;
    }
  }
  if (K == 2 && se.first != 0) {
    sum += 9 * (se.second - 1) + se.first;
  }
  if (K == 3) {
    for (int i = 2; i < se.second; i++) {
      if (i == 2) {
        sum += 81;
        continue;
      }
      sum += 81 * ue(i, 2) / 2;
    }
    sum += (se.first - 1) * 9 * (se.second - 1);
    if (th.first != 0) sum += 9 * (th.second - 1) + th.first;
  }
  cout << sum;
}
