#include <bits/stdc++.h>
using namespace std;
long long C(long long n, long long k) {
  if (n < k) return 0;
  long long ret = 1;
  for (long long i = n - k + 1; i <= n; i++) ret *= i;
  for (long long i = 1; i <= k; i++) ret /= i;
  return ret;
}
long long pow(long long a, long long b) {
  long long ret = 1;
  while (b--) ret *= a;
  return ret;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long k;
  string s;
  cin >> s >> k;
  long long n = s.size();
  if (n < k) cout << "0\n", exit(0);
  long long ans = C(n - 1, k) * pow(9, k);
  if (k == 1)
    ans += s[0] - '0';
  else if (k == 2)
    ans += (s[0] - '0' - 1) * C(n - 1, 1) * 9 + C(n - 2, 1) * 9 + (s[1] - '0');
  else if (k == 3)
    ans += (s[0] - '0' - 1) * C(n - 1, 2) * 81 + C(n - 2, 2) * 81 +
           (s[1] - '0' - 1) * C(n - 2, 1) * 9 + C(n - 3, 1) * 9 + (s[2] - '0');
  cout << ans << '\n';
  return 0;
}
