#include <bits/stdc++.h>
using namespace std;
using vi = vector<long long>;
using vvi = vector<vi>;
long long k, x, y;
vi a(100);
long long funck1(long long inp, long long nl) {
  long long flag = 0, ans = 0;
  if (a[nl - 2 - inp] == 0) return 0;
  for (long long i = inp; i < nl - 1; i++) {
    if (a[nl - 2 - i] != 0) {
      flag = 1;
      ans += a[nl - 2 - i];
      ans += 9LL * (nl - 2 - i);
      break;
    }
  }
  return ans;
}
long long funck2(long long inp, long long nl) {
  long long flag = 0, ans = 0;
  for (long long i = 0; i < nl - 1; i++) {
    if (a[nl - 2 - i] != 0) {
      flag++;
      if (flag == 1) {
        ans += (a[nl - 2 - i] - 1) * 9LL * (nl - 2 - i);
        ans += 81LL * (nl - 2 - i - 1) * (nl - 2 - i) / 2;
      }
      if (flag == 2) {
        ans += a[nl - 2 - i] + 9LL * (nl - 2 - i);
        break;
      }
    }
  }
  if (flag == 2) return ans;
  return 0;
}
int main() {
  long long ans = 0;
  string n;
  cin >> n >> k;
  long long nl = n.length();
  for (long long i = 0; i < nl; i++) {
    a[i] = n[nl - 1 - i] - 48;
  }
  long long k9 = 1;
  for (long long i = 0; i < k; i++) {
    k9 *= 9;
  }
  for (long long i = 0; i < nl - 1; i++) {
    if (i + 1 >= k) {
      long long ii = i + 1;
      long long k9a = k9;
      for (long long i = 0; i < k - 1; i++) {
        k9a *= ii - 1 - i;
      }
      if (k == 3) k9a /= 2;
      ans += k9a;
    }
  }
  if (k == 1) {
    ans += a[nl - 1];
  }
  if (k == 2) {
    ans += (a[nl - 1] - 1) * 9LL * (nl - 1);
    long long flag = 0;
    for (long long i = 0; i < nl - 1; i++) {
      if (a[nl - 2 - i] != 0) {
        ans += a[nl - 2 - i];
        ans += 9LL * (nl - 2 - i);
        break;
      }
    }
  }
  if (k == 3) {
    ans += (a[nl - 1] - 1LL) * 81LL * (nl - 1) * (nl - 2) / 2LL;
    long long flag = 0;
    flag = 0;
    ans += funck2(0, nl);
  }
  cout << ans << endl;
  return 0;
}
