#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;
ll comb(ll a, ll k) {
  ll ret = 1LL;
  for (int(i) = 0; (i) < (k); (i)++) {
    ret *= (a - i);
  }
  for (int(i) = 0; (i) < (k); (i)++) {
    ret /= (i + 1);
  }
  return ret;
}
ll pow(ll a, ll b) {
  ll ret = 1;
  for (int(i) = 0; (i) < (b); (i)++) ret *= a;
  return ret;
}
int main() {
  string N;
  cin >> N;
  ll K;
  cin >> K;
  ll res = comb(N.size() - 1, K) * (pow(9, K));
  vector<bool> ok(N.size() + 2, true);
  int now = 2;
  ok[0] = ok[1] = false;
  while (now < N.size() && N[now] == '0') {
    ok[now] = false;
    now++;
  }
  ok[now] = false;
  if (K == 1) {
    res += (N[0] - '0');
  } else if (K == 2) {
    for (int i = 1; i < N.size(); i++) {
      if ((N[0] - '0') - 1LL > 0) res += ((N[0] - '0') - 1LL) * 9LL;
      if (ok[i] == false)
        res += (N[i] - '0');
      else
        res += 9LL;
    }
  } else {
    for (int i = 1; i < N.size(); i++) {
      for (int j = i + 1; j < N.size(); j++) {
        if (ok[i] == false) {
          res += (N[0] - '0') * (N[j] - '0');
          if ((N[i] - '0') - 1LL > 0)
            res += (N[0] - '0') * ((N[i] - '0') - 1LL) * 9;
        } else
          res += (N[0] - '0') * 9LL * 9LL;
      }
    }
  }
  cout << res << endl;
  return 0;
}
