#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int k;
int choose(int n, int k, int nine) {
  if (n < k) return 0;
  int a = 1;
  for (int i = 0; i < nine; i++) {
    a *= 9;
  }
  if (k == 0) return a;
  if (k == 1)
    return n * a;
  else
    return (n - 1) * n / 2 * a;
}
void cn(string &n, int cnt) {
  for (long long i = 0; i < n.size(); ++i) {
    if (cnt == 0)
      n[i] = '9';
    else if (n[i] != '0') {
      cnt--;
      if (cnt == 0) n[i] -= 1;
    }
  }
  if (n[0] == '0') {
    n.erase(0, 1);
  }
}
int main() {
  string n;
  cin >> n;
  cin >> k;
  int cnt = 0;
  for (long long i = 0; i < n.size(); ++i) {
    if (n[i] != '0') cnt++;
  }
  if (cnt < k) cn(n, cnt);
  cnt = 0;
  for (long long i = 0; i < n.size(); ++i) {
    if (n[i] != '0') cnt++;
  }
  if (cnt < k) cn(n, cnt - 1);
  int keta = 0;
  int t = n.size();
  for (long long i = 0; i < t; ++i) {
    if (i == 0 || k > i) continue;
    keta += choose(i - 1, k - 1, k);
  }
  vector<int> fr(k), m(k);
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < n.size(); j++) {
      if (n[j] != '0') {
        fr[i] = n[j] - '0';
        m[j] = j + 1;
        i++;
        if (i == k) break;
      }
    }
  }
  int ans = keta;
  for (long long i = 0; i < k; ++i) {
    ans += (fr[i] - 1) * choose(t - m[i], k - i - 1, k - i - 1);
  }
  for (long long i = 0; i < k - 1; ++i) {
    ans += choose(t - m[i + 1], k - 1 - i, k - 1 - i);
  }
  ans++;
  cout << ans << endl;
  return 0;
}
