#include <bits/stdc++.h>
using namespace std;
unsigned long long combination(unsigned long long n, unsigned long long k) {
  unsigned long long ans = 1;
  for (int i = 0; i < k; ++i) {
    ans *= n - i;
  }
  for (int i = 0; i < k; ++i) {
    ans /= i + 1;
  }
  return ans;
}
int main() {
  string N;
  unsigned long long K;
  cin >> N >> K;
  unsigned long long len = N.size();
  unsigned long long ans = 0;
  unsigned long long l = 0;
  while (K > 0) {
    unsigned long long s = N[l] - '0' - 1;
    ans += combination(len - 1, K - 1) * s * pow(9, K - 1);
    for (unsigned long long i = 1; i <= len - K; ++i) {
      ans += combination(len - i - 1, K - 1) * 9 * pow(9, K - 1);
    }
    --K;
    ++l;
    --len;
  }
  cout << ans + 1 << endl;
  return 0;
}
