#include <bits/stdc++.h>
using namespace std;
long long int ncr(long long int n, long long int r) {
  if (r == 0) {
    return 1;
  } else if (r == 1) {
    return n;
  } else if (r == 2) {
    return n * (n - 1) / 2;
  } else if (r == 3) {
    return n * (n - 1) * (n - 2) / 6;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  string second;
  cin >> second;
  long long int k;
  cin >> k;
  long long int n = second.size();
  long long int ans = 0;
  long long int i;
  for (i = 0; i < n && k; ++i) {
    if (second[i] != '0') {
      ans += pow(9, k) * ncr(n - i - 1, k);
      if (second[i] - '0' - 1)
        ans += (second[i] - '0' - 1) * pow(9, k - 1) * ncr(n - i - 1, k - 1);
      k--;
    }
  }
  if (n - i > 0 || second[n - 1] != '0') ans++;
  cout << ans;
  return 0;
}
