#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
string s;
ll k;
ll res;
inline ll C(ll k, ll n) {
  if (k == 0) return 1;
  if (k == 1) return n;
  if (k == 2) return n * (n - 1) / 2;
  return n * (n - 1) * (n - 2) / 6;
}
inline ll mu(ll k) {
  if (k == 0) return 1;
  if (k == 1) return 9;
  if (k == 2) return 9 * 9;
  return 9 * 9 * 9;
}
void Solve(ll pos, ll num_l) {
  if (pos == ((ll)(s).size()) || num_l == 0) return;
  for (ll i = (0); i <= (s[pos] - '1'); ++i)
    res +=
        C(num_l - (i != 0), ((ll)(s).size()) - pos - 1) * mu(num_l - (i != 0));
  Solve(pos + 1, num_l - (s[pos] != '0'));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> s >> k;
  Solve(0, k);
  cout << res + 1;
}
