#include <bits/stdc++.h>
long long powz(long long v, long long k) {
  long long r(1), t(v);
  while (k) {
    if (k & 1) r *= t;
    t *= t;
    k >>= 1;
  }
  return r;
}
signed main() {
  std::string s;
  long long k;
  std::cin >> s >> k;
  long long n = s.size();
  std::function<long long(long long, long long)> f =
      [&](long long i, long long j) -> long long {
    if (j == 0) return 1;
    long long d = s[i] - '0';
    if (d == 0) return f(i + 1, j);
    long long x = (d - 1) * powz(9, j - 1);
    for (long long xx = 0; xx < (j - 1); xx++) {
      x *= n - i - 1 - xx;
      x /= xx + 1;
    }
    long long y = powz(9, j);
    for (long long yy = 0; yy < (j); yy++) {
      y *= n - i - 1 - yy;
      y /= yy + 1;
    }
    return f(i + 1, j - 1) + x + y;
  };
  std::cout << (f(0, k)) << '\n';
  return 0;
}
