#include <bits/stdc++.h>
using namespace std;
vector<pair<string, pair<int, int> > > vec;
long long comb(long long l, long long k) {
  if (k == 0) return 1;
  if (k == 1) return l;
  if (k == 2) return l * (l - 1) / 2;
  if (k == 3) return l * (l - 1) * (l - 2) / 6;
  return 0;
}
int main() {
  string N;
  long long K;
  cin >> N;
  scanf("%lld", &K);
  long long nine[4];
  nine[0] = 1;
  nine[1] = 9;
  nine[2] = 81;
  nine[3] = 729;
  long long len = N.length();
  if (len < K) cout << "0" << endl;
  long long res = 0;
  for (long long i = 0; i < len; i++) {
    long long a = N[i] - '0';
    if (a > 0 && K > 0) {
      res += (a - 1) * comb(len - 1 - i, K - 1) * nine[K - 1] +
             comb(len - 1 - i, K) * nine[K];
      K--;
    }
  }
  if (K == 0) res++;
  cout << res << endl;
  return 0;
}
