#include <bits/stdc++.h>
using namespace std;
struct combination {
  vector<int> fact;
  combination(int n) : fact(n + 1) {
    assert(n < 1000050);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
  }
  int operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n] / fact[k] / fact[n - k];
  }
} c(1000000);
int main() {
  vector<int> A(0);
  string s;
  cin >> s;
  int n = s.size();
  for (int i = n - 1; i >= 0; i--) {
    A.push_back(s[i] - '0');
  }
  int k;
  cin >> k;
  int m = n;
  vector<int> ks(0);
  vector<int> ketas(0);
  for (int i = m - 1; i >= 0; i--) {
    if (k > 0 && A[i] != 0) {
      k--;
      ks.push_back(A[i]);
      ketas.push_back(i + 1);
    }
  }
  int sum = 0;
  int size = ketas.size();
  if (ketas[0] > size) {
    sum += c(ketas[0] - 1, size) * pow(9, size);
  }
  for (int i = 0; i < size; i++) {
    if (size - 1 == i) {
      sum += ks[i];
      break;
    } else {
      sum += (ks[i] - 1) * pow(9, size - i - 1) * c(ketas[i] - 1, size - i - 1);
    }
  }
  cout << sum << endl;
  return 0;
}
