#include <bits/stdc++.h>
using namespace std;
long long fact(long long n, long long cnt) {
  long long ret = 1;
  for (long long x = (long long)n - cnt; x < (long long)(n); x++) {
    ret *= (x + 1);
  }
  return ret;
}
long long fact(long long n) { return fact(n, n); }
long long combi(long long n, long long r) { return fact(n, r) / fact(r); }
long long calc(string value, int keta) {
  long long n0 = stoll(value.substr(0, 1));
  if (keta == 1) {
    return (value.length() - 1) * 9 + n0;
  } else {
    long long nmax = calc(value.substr(1, value.length() - 1), keta - 1);
    long long n2nd = (n0 - 1) *
                     combi(value.length() - 1, (long long)(keta - 1)) *
                     pow(9, keta - 1);
    long long n3rd = combi(value.length() - 1, (long long)keta) * pow(9, keta);
    return nmax + n2nd + n3rd;
  }
}
int main() {
  string n;
  int k;
  cin >> n >> k;
  cout << fixed << calc(n, k) << endl;
  return 0;
}
