#include <bits/stdc++.h>
using namespace std;
string N;
int K;
long long combi(long long a, long long b) {
  if (b == 1) return a;
  if (b == 2) return a * (a - 1) / 2;
  return a * (a - 1) * (a - 2) / 6;
}
long long power(int a) {
  if (a == 0)
    return 1;
  else
    return 9 * power(a - 1);
}
long long count(string N, int K) {
  int d = N.size();
  if (K > d) return 0;
  long long res = 0;
  res += power(K) * combi(d - 1, K);
  if (K == 1) {
    res += (N[0] - '0');
    return res;
  } else {
    res += ((N[0] - '0') - 1) * power(K - 1) * combi(d - 1, K - 1);
    string S;
    for (int i = 1; i < d; i++) {
      S += N[i];
    }
    res += count(S, K - 1);
    return res;
  }
}
int main() {
  cin >> N >> K;
  cout << count(N, K) << endl;
  return 0;
}
