#include <bits/stdc++.h>
using namespace std;
const int64_t LINF = 9187201950435737471;
const int64_t nLINF = -9187201950435737472;
const int INF = 2139062143;
const int nINF = -2139062144;
const uint64_t ULINF = numeric_limits<uint64_t>::max();
const int MAXN = 2e4 + 15;
const int64_t MOD = 1e9;
const double EPS = 1e-9;
const double PI = acos(-1);
auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rnd(seed);
inline void IO() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
}
template <typename T>
istream& operator>>(istream& in, vector<T>& a) {
  for (auto& i : a) in >> i;
  return in;
}
template <typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
  for (auto& i : a) {
    out << i << " ";
  }
  return out;
}
template <typename T, typename D>
istream& operator>>(istream& in, pair<T, D>& a) {
  in >> a.first >> a.second;
  return in;
}
template <typename T, typename D>
ostream& operator<<(ostream& out, const pair<T, D>& a) {
  out << a.first << " " << a.second;
  return out;
}
inline void solve() {
  string s;
  int64_t k;
  cin >> s >> k;
  int64_t ans = 0;
  for (int64_t i = k; i < (int64_t)(s.size()); ++i) {
    if (k == 1) {
      ans += 9LL;
    } else if (k == 2) {
      ans += 9LL * (i - 1) * 9LL;
    } else {
      ans += 81LL * 9LL * (i - 1LL) * (i - 2LL) / 2LL;
    }
  }
  int64_t n = (int64_t)(s.size());
  if (k == 1) {
    ans += s[0] - '0';
  } else if (k == 2 && n >= 2) {
    assert(false);
    ans += (s[0] - '0' - 1) * (n - 1) * 9LL;
    ans += (n - 2) * 9LL;
    ans += (s[1] - '0');
  } else if (k == 3 && n >= 3) {
    ans += (s[0] - '0' - 1) * (n - 1) * (n - 2) / 2LL * 81LL;
    ans += (n - 2) * (n - 3) / 2 * 81LL;
    ans += (s[1] - '0' - 1) * (n - 2) * 9LL;
    ans += (n - 3) * 9LL;
    ans += (s[2] - '0');
  }
  cout << ans;
}
signed main() {
  IO();
  int64_t t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
