#include <bits/stdc++.h>
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
using namespace std;
using ll = long long;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
ll devc(ll x, ll y) { return (x + y - 1) / y; }
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
  string N;
  ll K;
  cin >> N >> K;
  ll L = (ll)N.size();
  vector<vector<vector<ll>>> f(L + 1, vector<vector<ll>>(4, vector<ll>(2, 0)));
  f[0][0][0] = 1;
  for (ll i = 1; i <= (L); ++i) {
    for (ll j = 0; j < (4); ++j) {
      f[i][j][0] += f[i - 1][j][0];
      if (j >= 1) f[i][j][0] += f[i - 1][j - 1][0];
      f[i][j][1] += f[i - 1][j][1] + f[i - 1][j][0];
      if (j >= 1)
        f[i][j][1] += f[i - 1][j - 1][1] * 9 +
                      f[i - 1][j - 1][0] * max(N[i] - '0' - 1, 0);
    }
  }
  cout << (f[L][K][0] + f[L][K][1]) << '\n';
  return 0;
}
