#include <bits/stdc++.h>
using namespace std;
using ll = long long;
unsigned choose(unsigned n, unsigned k) {
  if (k > n) return 0;
  if (k * 2 > n) k = n - k;
  if (k == 0) return 1;
  int result = n;
  for (int i = 2; i <= k; ++i) {
    result *= (n - i + 1);
    result /= i;
  }
  return result;
}
int NKmin(string S, int K) {
  int size = S.length();
  ll ans = 0;
  if (K == 1) {
    if (size > K) {
      ans += choose(size - 1, K) * pow(9, K);
    }
    ans += (S[0] - '0');
  } else {
    ans += choose(size - 1, K) * pow(9, K);
    cout << choose(size - 1, K) << endl;
    ans += (S[0] - '1') * choose(size - 1, K - 1) * pow(9, K - 1);
    string S1;
    for (ll i = 0; i < (size - 1); i++) {
      S1.push_back(S[i + 1]);
    }
    ans += NKmin(S1, K - 1);
  }
  return ans;
}
int main() {
  string S;
  cin >> S;
  int K;
  cin >> K;
  int ans = NKmin(S, K);
  cout << ans << endl;
}
