#include <bits/stdc++.h>
int main() {
  std::string N;
  int K;
  std::cin >> N >> K;
  if (K > N.size()) {
    std::cout << 0 << std::endl;
    return 0;
  }
  std::vector<int> v(N.size());
  for (int i = 0; i < N.size(); i++) {
    char c = N[i];
    v[i] = std::stoi(&c);
  }
  long long sum = 0LL;
  if (K == 1) {
    sum += v[0];
    sum += 9 * (v.size() - 1);
  } else if (K == 2) {
    sum += v[1] + 9 * (v.size() - 2) + (v[0] - 1) * 9 * (v.size() - 1);
    sum += (v.size() - 1) * (v.size() - 2) / 2 * 9 * 9;
  } else if (K == 3) {
    sum += v[2] + 9 * (v.size() - 3) + (v[1] - 1) * 9 * (v.size() - 2) +
           (v[0] - 1) * 9 * 9 * (v.size() - 1) * (v.size() - 2) / 2;
    sum += (v.size() - 1) * (v.size() - 2) * (v.size() - 3) / 6 * 9 * 9 * 9;
  }
  std::cout << sum << std::endl;
  return 0;
}
