#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 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 (K == 1) {
    ll ans = 0;
    ans += 9 * (M - 1);
    ans += N[M];
    cout << ans << endl;
    return 0;
  } else if (K == 2) {
    if (M < K) {
      cout << 0 << endl;
      return 0;
    }
    ll ans = 0;
    ans += 9 * (N[M] - 1) * (M - 1);
    ans += N[M - 1];
    ans += 9 * (M - 2);
    ans += 9 * 9 * (M - 1) * (M - 2) / 2;
    cout << ans << endl;
    return 0;
  } else {
    if (M < K) {
      cout << 0 << endl;
      return 0;
    }
    ll ans = 0;
    ans += 9 * 9 * (N[M] - 1) * (M - 1) * (M - 2) / 2;
    ans += 9 * 9 * (M - 2) * (M - 3) / 2;
    ans += N[M - 2];
    ans += 9 * (M - 3);
    ans += 9 * (N[M - 1] - 1) * (M - 2);
    ans += 9 * 9 * 9 * (M - 1) * (M - 2) * (M - 3) / 6;
    cout << ans << endl;
    return 0;
  }
  return 0;
}
