#include <bits/stdc++.h>
using namespace std;
int fact(int n);
int nCr(int n, int r) { return fact(n) / (fact(r) * fact(n - r)); }
int fact(int n) {
  int res = 1;
  for (int i = 2; i <= n; i++) res = res * i;
  return res;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  double n;
  int k;
  cin >> n >> k;
  int d = floor(log10(n)) + 1;
  if (d < k) {
    cout << 0 << endl;
    return 0;
  }
  long long ans = 0;
  ans += pow(9, k) * nCr(d - 1, k);
  int m = (int)floor(n / pow(10, d - 1));
  if (d >= 3) {
    ans += (long long)m * pow(9, k - 1) * nCr(d - 2, k - 1);
  }
  int mm = (int)floor((n - m * pow(10, d - 1)) / pow(10, d - 2));
  long long s = (long long)9 * (m - 1) + mm;
  if (k == 2)
    ans += s;
  else {
    int mmm = (int)floor(n - m * pow(10, d - 1) - mm * pow(10, d - 2)) /
              pow(10, d - 3);
    ans += (long long)s * (9 * (d - 3) + mmm);
  }
  cout << ans << endl;
}
