#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long MAX = 510000;
const long long MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (long long i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long COM(long long n, long long k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
signed main() {
  long long k;
  string s;
  cin >> s >> k;
  COMinit();
  if (k == 1) {
    cout << (long long)(s[0] - '0') + 9 * (s.size() - 1) << endl;
  }
  if (k == 2) {
    long long x = 9 * 9 * COM(s.size() - 1, 2);
    long long y = ((long long)(s[0] - '0') - 1) * 9 * (s.size() - 1);
    cout << x + y + (long long)(s[1] - '0') + 9 * (s.size() - 2) << endl;
  }
  if (k == 3) {
    long long x = 9 * 9 * 9 * COM(s.size() - 1, 3);
    x += ((long long)(s[0] - '0') - 1) * 9 * 9 * COM(s.size() - 1, 2);
    x += 9 * max((long long)(s[1] - '0') - 1, (long long)0) * (s.size() - 2) +
         (long long)(s[2] - '0');
    if ((long long)(s[2] - '0') != 0) {
      x += 9 * (s.size() - 3);
    }
    cout << x << endl;
  }
  return 0;
}
