#include <bits/stdc++.h>
using namespace std;
int func(const string& num, const int k) {
  int n = 0;
  const auto size = num.size();
  const int top = num.front() - '0';
  const auto next = num.substr(1, size - 1);
  if (top != 0) {
    if (k == 1) {
      return (size - 1) * 9 + top;
    }
    if (k == 2) {
      n = (size - 1) * 9 * top;
      n += func(next, k - 1);
    }
    if (k == 3) {
      n = ((size - 1) * (size - 2) / 2) * 9 * top;
      n += func(next, k - 1);
    }
  }
  if (size <= k) return n;
  return n + func(num.substr(1, size - 1), k);
}
int main() {
  string n;
  cin >> n;
  int k;
  cin >> k;
  int ans = func(n, k);
  cout << ans << endl;
  return 0;
}
