#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
using ldouble = long double;
int count(vector<int>& N, int M) { return N[M] + 9 * (M - 1); }
int msn0(vector<int>& N, int M) {
  while (N[M] == 0 && M > 0) --M;
  return M;
}
int count2(vector<int>& N, int M) {
  ll ans = 0;
  ans += count(N, msn0(N, M - 1));
  ans += 9 * (N[M] - 1) * (M - 1);
  ans += 81 * (M - 1) * (M - 2) / 2;
  return ans;
}
int count3(vector<int>& N, int M) {
  ll ans = 0;
  ans += count2(N, M - 1);
  ans += 81 * (N[M] - 1) * (M - 1) * (M - 2) / 2;
  ans += 81 * 9 * (M - 1) * (M - 2) * (M - 3) / 6;
  return ans;
}
int main() {
  string s;
  int K;
  int M;
  cin >> s >> K;
  M = s.size();
  vector<int> N(M + 1);
  for (int i = 0; i < M; ++i) N[M - i] = s[i] - '0';
  if (M < K)
    cout << 0 << endl;
  else if (K == 1)
    cout << count(N, M) << endl;
  else if (K == 2)
    cout << count2(N, M) << endl;
  else
    cout << count3(N, M) << endl;
  return 0;
}
