#include <bits/stdc++.h>
using namespace std;
long long ans = 0;
long long nCr(long long n, long long r) {
  long long ans = 1;
  for (long long i = n; i > n - r; --i) {
    ans = ans * i;
  }
  for (long long i = 1; i < r + 1; ++i) {
    ans = ans / i;
  }
  return ans;
}
void che(string S, long long depth, long long noko) {
  if (depth == S.size() - 1) {
    if (noko == 0) ans += (S[depth] - '0');
  } else if (noko == 0)
    return;
  else {
    if (S[depth] == '0')
      che(S, depth + 1, noko);
    else {
      long long ai = S[depth] - '0';
      ans += (ai - 1) * nCr(S.size() - depth, noko - 1) * pow(9, noko - 1);
      che(S, depth + 1, noko - 1);
    }
  }
}
signed main() {
  long long K;
  string S;
  cin >> S >> K;
  if (S.size() - 1 >= K) ans += nCr(S.size() - 1, K) * pow(9, K);
  che(S, 0, K);
  cout << ans << endl;
}
