#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;
const ll MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; ++i) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
ll COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll Str2Long(string s) {
  reverse((s).begin(), (s).end());
  ll n = 0;
  for (ll i = 0; i < s.size(); ++i) {
    n += (s[i] - '0') * pow(10, i);
  }
  return n;
}
ll calc1(string s) {
  ll top = s[0] - '0';
  ll res = top;
  if (s.size() > 1) res += COM(s.size() - 1, 1) * 9;
  return res;
}
ll calc2(string s) {
  ll top = s[0] - '0';
  ll ans;
  ll keta = s.size();
  if (keta == 2)
    ans = Str2Long(s) - Str2Long(s) / 10 - 9;
  else if (keta < 2)
    ans = 0;
  else {
    ans = COM(keta - 1, 2) * 81;
    ans += (top - 1) * COM(keta - 1, 1) * 9;
    s.erase(s.begin());
    ans += calc1(s);
  }
  return ans;
}
int main() {
  string n;
  cin >> n;
  ll k;
  cin >> k;
  COMinit();
  ll ans;
  ll keta = n.size();
  if (k == 1)
    ans = calc1(n);
  else if (k == 2)
    ans = calc2(n);
  else {
    ll top = n[0] - '0';
    string tmp = n;
    tmp.erase(tmp.begin());
    if (keta == 3) {
      ans = calc2(tmp) + (top - 1) * 81;
    } else if (keta < 3)
      ans = 0;
    else {
      ans = COM(keta - 1, 3) * 729;
      ans += (top - 1) * COM(keta - 1, 2) * 81;
      ans += calc2(tmp);
    }
  }
  cout << ans << endl;
}
