#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long>> prime_factorize(long long n) {
  vector<pair<long long, long long>> res;
  for (long long p = 2; p * p <= n; ++p) {
    if (n % p != 0) continue;
    int num = 0;
    while (n % p == 0) {
      ++num;
      n /= p;
    }
    res.push_back(make_pair(p, num));
  }
  if (n != 1) res.push_back(make_pair(n, 1));
  return res;
}
const int COMMAX = 210000;
long long fac[COMMAX], finv[COMMAX], inv[COMMAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < COMMAX; i++) {
    fac[i] = fac[i - 1] * i % 1000000007;
    inv[i] = 1000000007 - inv[1000000007 % i] * (1000000007 / i) % 1000000007;
    finv[i] = finv[i - 1] * inv[i] % 1000000007;
  }
}
long long 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] % 1000000007) % 1000000007;
}
vector<int> v;
int main() {
  COMinit();
  string s;
  int k, n;
  cin >> s >> k;
  n = s.size();
  v.resize(n);
  for (int i = 0, i_l = (n); i < i_l; i++) {
    v[i] = s[i] - '0';
  }
  int cnt = 0;
  if (k == 1) {
    cnt = 9 * (n - 1) + v[0];
  }
  if (k == 2) {
    cnt += v[1] + 9 * (n - 2);
    cnt += ((v[0] - 1 < 0) ? 0 : v[0] - 1) * 9 * (n - 1);
    cnt += COM(n - 1, 2) * 9 * 9;
  }
  if (k == 3) {
    cnt += v[2] + 9 * (n - 3);
    cnt += ((v[1] - 1 < 0) ? 0 : v[1] - 1) * 9 * (n - 2);
    cnt += COM(n - 2, 2) * 9 * 9;
    cnt += ((v[0] - 1 < 0) ? 0 : v[0] - 1) * COM(n - 1, 2) * 9 * 9;
    cnt += COM(n - 1, 3) * 9 * 9 * 9;
  }
  cout << cnt;
  return 0;
}
