#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (a < b) {
    swap(a, b);
  }
  return (a % b == 0) ? b : gcd(a, a % b);
}
int lcm(int a, int b) { return (a * b) / gcd(a, b); }
long long combination(int parent, int choice) {
  if (choice == 0) {
    return 1;
  }
  long long ans = 1;
  for (int i = (int)(1); i < (int)(choice + 1); i++) {
    ans *= parent + 1 - i;
    ans /= i;
  }
  return ans;
}
long long solve(string target, int depth) {
  long long ans = 1;
  int length = target.length();
  for (int i = 0; i < (int)(length); i++) {
    if (depth < 0) break;
    int target_decimal = target.at(i) - '0';
    if (target_decimal > 0) {
      target_decimal--;
      ans +=
          target_decimal * combination(length - i - 1, depth) * pow(9, depth);
      for (int j = (int)(i + 1); j < (int)(length); j++) {
        ans += 9 * combination(length - j - 1, depth) * pow(9, depth);
      }
      depth--;
    }
  }
  return ans;
}
int main() {
  string s;
  int k;
  cin >> s >> k;
  cout << solve(s, k - 1) << endl;
}
