#include <bits/stdc++.h>
using namespace std;
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 (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
long long gcd(long long n, long long m) { return (m ? gcd(m, n % m) : n); }
long long lcm(long long n, long long m) { return n / gcd(n, m) * m; }
long long mod = 1000000007;
long long fac[2000010];
long long modinv(long long a) {
  long long b = mod, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= mod;
  if (u < 0) u += mod;
  return u;
}
void modfac() {
  fac[0] = 1;
  for (long long i = 1; i < 2000010; i++) {
    fac[i] = (fac[i - 1] * i) % mod;
  }
}
long long modperm(long long n, long long k) {
  if (n < 0 || k < 0 || n < k)
    return 0;
  else
    return (fac[n] * modinv(fac[n - k])) % mod;
}
long long modcomb(long long n, long long k) {
  if (n < 0 || k < 0 || n < k)
    return 0;
  else
    return ((fac[n] * modinv(fac[k])) % mod * modinv(fac[n - k])) % mod;
}
int main() {
  string s;
  int k;
  cin >> s >> k;
  int n = s.size();
  int ans = 0;
  int c = s[0] - '0';
  if (k == 1) {
    ans += 9 * (n - 1);
    ans += c;
  }
  if (k == 2 && n > 1) {
    ans += 81 * (n - 1) * (n - 2) / 2;
    ans += (c - 1) * (n - 1) * 9;
    ans += 9 * (n - 2);
    ans += (s[1] - '0');
  }
  if (k == 3 && n > 2) {
    ans += 729 * (n - 1) * (n - 2) * (n - 3) / 6;
    ans += (c - 1) * 81 * (n - 1) * (n - 2) / 2;
    ans += 81 * (n - 2) * (n - 3) / 2;
    ans += (s[1] - '0' - 1) * (n - 2) * 9;
    ans += 9 * (n - 3);
    ans += (s[2] - '0');
  }
  cout << ans << endl;
}
