#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long N = 1e6 + 5;
const long long M = 1e3 + 5;
int n, m, k, T;
template <class T>
T read(T &x) {
  T f = 1;
  x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch - '0');
    ch = getchar();
  }
  x *= f;
}
long long qpow(long long a, long long b, long long p) {
  long long res = 1;
  while (b) {
    if (b & 1) res = (res * a) % p;
    a = (a * a) % p;
    b >>= 1;
  }
  return res;
}
long long ex_gcd(long long a, long long b, long long &x, long long &y) {
  if (!b) {
    x = 1, y = 0;
    return a;
  }
  long long res = ex_gcd(b, a % b, x, y);
  long long t = x;
  x = y;
  y = t - a / b * y;
  return res;
}
long long prime[N + 10], phi[N + 10], mou[N + 10], cnt_prime;
bool judgeprime[N + 10];
void ouler() {
  phi[1] = mou[1] = 1;
  for (int i = 2; i <= N; i++) {
    if (!judgeprime[i]) prime[cnt_prime++] = i, phi[i] = i - 1, mou[i] = -1;
    for (int j = 0; j < cnt_prime && i * prime[j] <= N; j++) {
      judgeprime[i * prime[j]] = 1;
      if (i % prime[j] == 0) {
        phi[i * prime[j]] = phi[i] * prime[j];
        mou[i * prime[j]] = 0;
        break;
      } else {
        mou[i * prime[j]] = -mou[i];
        phi[i * prime[j]] = phi[i] * (prime[j] - 1);
      }
    }
  }
}
long long C2(long long n) { return n * (n - 1) / 2; }
long long C3(long long n) { return n * (n - 1) * (n - 2) / 6; }
long long a[N], sum[N], ans;
int main() {
  string s;
  cin >> s;
  cin >> k;
  int len = s.size();
  if (k == 1ll) {
    ans += s[0] - '0';
    ans += 9 * (len - 1);
  }
  if (k == (long long)2) {
    if (len >= k) {
      ans += (s[1] - '0') + (len - 2) * 9 + (s[0] - '0' - 1) * 9 * (len - 1);
      ans += C2(len - 1) * 81;
    }
  }
  if (k == (long long)3) {
    if (len >= k) {
      ans += (s[2] - '0') + (len - 3) * 9 + (s[1] - '0' - 1) * (len - 2) * 9 +
             C2(len - 2) * 81 + (s[0] - '0' - 1) * C2(len - 1) * 81;
      ans += C3(len - 1) * 729;
    }
  }
  cout << ans << endl;
  return 0;
}
