#include <bits/stdc++.h>
long long count1(long long first, long long size) {
  if (size < 1) return 0;
  return 9 * (size - 1) + first;
}
long long count2(long long first, long long second, long long size) {
  if (size < 2) return 0;
  return (size - 1) * (size - 2) / 2 * 81 + (first - 1) * count1(9, size - 1) +
         count1(second, size - 1);
}
long long count3(long long first, long long second, long long third,
                 long long size) {
  if (size < 3) return 0;
  return (size - 1) * (size - 2) * (size - 3) / 6 * 729 +
         (first - 1) * count2(9, 9, size - 1) + count2(second, third, size - 1);
}
int main() {
  std::string n;
  std::cin >> n;
  int k;
  std::cin >> k;
  if (k > n.size()) {
    std::cout << 0 << std::endl;
    return 0;
  }
  if (k == 1) {
    std::cout << count1(n[0] - '0', n.size()) << std::endl;
    return 0;
  }
  if (k == 2) {
    std::cout << count2(n[0] - '0', n[1] - '0', n.size()) << std::endl;
    return 0;
  }
  if (k == 3) {
    std::cout << count3(n[0] - '0', n[1] - '0', n[2] - '0', n.size())
              << std::endl;
    return 0;
  }
}
