#include <bits/stdc++.h>
int ctoi(char c) {
  switch (c) {
    case '1':
      return 1;
    case '2':
      return 2;
    case '3':
      return 3;
    case '4':
      return 4;
    case '5':
      return 5;
    case '6':
      return 6;
    case '7':
      return 7;
    case '8':
      return 8;
    case '9':
      return 9;
    default:
      return 0;
  }
}
long long GetOneDigitNum(const std::string& str) {
  return (static_cast<int>(str.size()) - 1) * 9 + ctoi(str.front());
}
long long GetTwoDigitNum(const std::string& str) {
  const int size = static_cast<int>(str.size());
  if (size == 1) {
    return 0;
  }
  long long sum = (size - 1) * (size - 2) * 81 / 2;
  for (int i = 1; i < ctoi(str.front()); ++i) {
    sum += 9 * (size - 1);
  }
  sum += GetOneDigitNum(str.substr(1));
  return sum;
}
long long GetThreeDigitNum(const std::string& str) {
  const int size = static_cast<int>(str.size());
  if (size < 3) {
    return 0;
  }
  long long sum = (size - 1) * (size - 2) * (size - 3) * 243 / 2;
  for (int i = 1; i < ctoi(str.front()); ++i) {
    sum += (size - 1) * (size - 2) * 81 / 2;
  }
  sum += GetTwoDigitNum(str.substr(1));
  return sum;
}
int main() {
  std::string n;
  int k = 0;
  std::cin >> n >> k;
  if (k == 1) {
    std::cout << GetOneDigitNum(n) << std::endl;
  } else if (k == 2) {
    std::cout << GetTwoDigitNum(n) << std::endl;
  } else {
    std::cout << GetThreeDigitNum(n) << std::endl;
  }
}
