#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;
static const ll INF = 1001001001;
static const ll LLINF = 1001001001001001001;
void debug_out() {}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
ll digits_recurse(ll x) {
  if (x == 0) return 0;
  return 1 + digits_recurse(x / 10);
}
ll digits(ll x) {
  if (x == 0) return 1;
  return digits_recurse(x);
}
ll pow(ll x, ll y) {
  if (y <= 0) return 1;
  return x * pow(x, y - 1);
}
int run(istream& in, ostream& out) {
  ll N, K;
  in >> N;
  in >> K;
  ll ans = 0;
  ll num_digits = digits(N);
  ll power_of_10 = pow(10, num_digits - 1);
  ll power_of_100 = pow(10, num_digits - 2);
  ll power_of_1000 = pow(10, num_digits - 3);
  for (ll k = 0; k < (K); ++k) {
    switch (k) {
      case 0: {
        ll top = N / power_of_10;
        ans += top + (num_digits - 1) * 9;
        break;
      }
      case 1: {
        if (num_digits < 2) break;
        ll top2 = N / power_of_100;
        ll top2_1 = top2 / 10;
        ll top2_2 = top2 % 10;
        ans += top2_2 + 9 * (top2_1 - 1) +
               (num_digits - 1) * (num_digits - 2) * 9 * 9 / 2;
        break;
      }
      case 2: {
        if (num_digits < 3) break;
        ll top3 = N / power_of_1000;
        ll top3_1 = top3 / 100;
        ll top3_2 = top3 % 100 / 10;
        ll top3_3 = top3 % 100 % 10;
        ans += top3_3 + 9 * (top3_2 - 1) + 9 * 9 * (top3_1 - 1) +
               (num_digits - 1) * (num_digits - 2) * (num_digits - 3) * 9 * 9 *
                   9 / 6;
        break;
      }
    }
  }
  out << ans << endl;
  return 0;
}
int main() { return run(cin, cout); }
