#include <bits/stdc++.h>
using namespace std;
long long dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
long long kaijo[2000010];
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
bool prime(long long a) {
  if (a == 1) return false;
  for (long long i = 2; i * i <= a; i++) {
    if (a % i == 0) return false;
  }
  return true;
}
void init_fact() {
  kaijo[0] = 1;
  for (long long i = 1; i <= 2000000; i++) {
    kaijo[i] = kaijo[i - 1] * i;
    kaijo[i] %= 1000000007;
  }
}
long long modpow(long long a, long long b) {
  if (b == 0) return 1;
  if (b % 2) return modpow(a, b - 1) * a % 1000000007;
  long long memo = modpow(a, b / 2);
  return memo * memo % 1000000007;
}
long long comb(long long a, long long b) {
  if (!kaijo[0]) init_fact();
  return kaijo[a] * modpow(kaijo[a - b], 1000000007 - 2) % 1000000007 *
         modpow(kaijo[b], 1000000007 - 2) % 1000000007;
}
long long inv(long long x) {
  x = modpow(x, 1000000007 - 2);
  return x;
}
bool kosa(double ax, double ay, double bx, double by, double cx, double cy,
          double dx, double dy) {
  double ta = (cx - dx) * (ay - cy) + (cy - dy) * (cx - ax);
  double tb = (cx - dx) * (by - cy) + (cy - dy) * (cx - bx);
  double tc = (ax - bx) * (cy - ay) + (ay - by) * (ax - cx);
  double td = (ax - bx) * (dy - ay) + (ay - by) * (ax - dx);
  return tc * td < 0 && ta * tb < 0;
}
string n;
long long k, ans;
signed main() {
  cin >> n >> k;
  init_fact();
  for (long long i = k; i <= n.size(); i++) {
    if (i != n.size()) {
      if (k == 1) {
        ans += 9;
      }
      if (k == 2) {
        ans += (i - 1) * 81;
      }
      if (k == 3) {
        ans += ((i - 1) * (i - 2) / 2) * 729;
      }
    } else {
      if (k == 1) {
        ans += (n[0] - '0');
      }
      if (k == 2) {
        ans += (i - 1) * 81;
        ans -= (i - 1) * 9 * (9 - (n[0] - '0'));
        for (long long j = 1; j < n.size(); j++) {
          if (n[j] != '9') {
            ans -= (9 - (n[j] - '0'));
            break;
          }
        }
      }
      if (k == 3) {
        bool flag = false;
        ans += ((i - 1) * (i - 2) / 2) * 729;
        ans -= (9 - (n[0] - '0')) * ((i - 1) * (i - 2) / 2) * 81;
        long long num = 1;
        for (long long j = 1; j < n.size(); j++) {
          if (!flag) {
            ans -= (9 - (n[j] - '0')) * (n.size() - i - 1) * 9;
            flag = true;
          } else {
            ans -= (9 - (n[j] - '0'));
          }
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
