#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::atoi(&c);
  }
  long long sum = 0LL;
  if (K == 1) {
    sum += v[0];
    sum += 9LL * (v.size() - 1LL);
  } else if (K == 2) {
    sum += (long long)v[1] + 9LL * (v.size() - 2LL) +
           (v[0] - 1LL) * 9LL * (v.size() - 1LL);
    sum += (long long)(v.size() - 1LL) * (v.size() - 2LL) / 2LL * 9LL * 9LL;
  } else if (K == 3) {
    sum += (long long)v[2] + 9LL * (v.size() - 3LL) +
           (v[1] - 1LL) * 9LL * (v.size() - 2LL) +
           9LL * 9LL * (v.size() - 2LL) * (v.size() - 3LL) / 2LL +
           (v[0] - 1LL) * 9LL * 9LL * (v.size() - 1LL) * (v.size() - 2LL) / 2LL;
    sum += (long long)(v.size() - 1LL) * (v.size() - 2LL) * (v.size() - 3LL) /
           6LL * 9LL * 9LL * 9LL;
  }
  std::cout << sum << std::endl;
  return 0;
}
