#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll count(ll n, ll k) {
  if (n < k) return 0;
  ll res = 1;
  for (int((i)) = (0); ((i)) < ((k)); ((i))++) {
    res *= 9;
    res *= n - i;
    res /= (i + 1);
  }
  return res;
}
int main() {
  string N;
  ll K;
  cin >> N >> K;
  ll M = N.size();
  ll res = 0;
  for (int((i)) = (0); ((i)) < ((M - 1)); ((i))++) {
    res += 9 * count(i, K - 1);
  }
  if (K == 1) {
    res += N[0] - '0';
  } else {
    int befnone0 = 0, none0 = 1;
    for (int(i) = (1); (i) < (K); (i)++) {
      while (none0 < M && N[none0] == '0') none0++;
      if (none0 == M) break;
      res += (N[befnone0] - '0' - 1) * count(M - befnone0 - 1, K - i);
      res += count(M - none0 - 1, K - i);
      if (K == 2) res += (N[none0] - '0') * count(M - none0 - 1, K - i - 1);
      befnone0 = none0;
      none0++;
    }
    if (K == 3 && none0 != M) {
      res += N[none0] - '0';
    }
  }
  cout << res << endl;
  return 0;
}
