#include <bits/stdc++.h>
using namespace std;
int64_t comb(int n, int k) {
  int64_t result = 1;
  if (n >= 0) {
    for (int64_t i = 1; i <= k; i++) {
      result *= n--;
      result /= i;
    }
  } else
    result = 0;
  return result;
}
int counter(int n, int k, int size, string &N) {
  return k ? (N[size - n] - '0') ? pow(9, k) * comb(n - 1, k) +
                                       ((N[size - n] - '0') - 1) *
                                           pow(9, k - 1) * comb(n - 1, k - 1) +
                                       counter(n - 1, k - 1, size, N)
                                 : counter(n - 1, k, size, N)
           : 1;
}
int main() {
  string N;
  int k;
  cin >> N >> k;
  int len = N.length();
  cout << counter(len, k, len, N) << endl;
  return 0;
}
