#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) { return y ? gcd(y, x % y) : x; }
class EAlmostEverywhereZero {
 public:
  int f1(int len, int a) { return (len - 1) * 9 + a; }
  int f2(int len, int a, int b) {
    return (len - 1) * (len - 2) / 2 * 9 * 9 + (a - 1) * (len - 1) * 9 +
           f1(len - 1, b);
  }
  int f3(int len, int a, int b, int c) {
    return (len - 1) * (len - 2) * (len - 3) / 6 * 9 * 9 * 9 +
           (a - 1) * (len - 1) * (len - 2) / 2 * 9 * 9 + f2(len - 1, b, c);
  }
  void solve(std::istream& in, std::ostream& out) {
    string N;
    int K;
    in >> N >> K;
    long long len = N.size();
    long long ans = 0;
    if (len >= K) {
      switch (K) {
        case 1:
          ans = f1(len, N[0] - '0');
          break;
        case 2:
          ans = f2(len, N[0] - '0', N[1] - '0');
          break;
        case 3:
          ans = f3(len, N[0] - '0', N[1] - '0', N[2] - '0');
          break;
      }
    }
    out << ans << '\n';
  }
};
int main() {
  EAlmostEverywhereZero solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}
