#include <bits/stdc++.h>
using namespace std;
string N;
int K;
int main() {
  int i, j;
  int top;
  int second, si = 0;
  int third, ti = 0;
  int keta;
  long long int ret = 0;
  cin >> N;
  cin >> K;
  top = N[0] - '0';
  keta = N.length();
  for (i = 1; i < keta; i++) {
    if (N[i] - '0' > 0) {
      second = N[i] - '0';
      si = keta - i;
      i++;
      break;
    }
  }
  for (; i < keta; i++) {
    if (N[i] - '0' > 0) {
      third = N[i] - '0';
      ti = keta - i;
      break;
    }
  }
  switch (K) {
    case 1:
      ret = 9LL * (keta - 1) + top;
      break;
    case 2:
      ret = (long long int)9 * 9 * (keta - 1) * (keta - 2) / 2;
      ret += (long long int)(top - 1) * 9 * (keta - 1);
      if (second) {
        ret += (long long int)9 * (si - 1) + second;
      }
      break;
    case 3:
      ret = (long long int)9 * 9 * 9 * (keta - 1) * (keta - 2) * (keta - 3) / 6;
      ret += (long long int)(top - 1) * 9 * 9 * (keta - 1) * (keta - 2) / 2;
      if (second) {
        ret += (long long int)9 * 9 * (si - 1) * (si - 2) / 2;
        ret += (long long int)(second - 1) * 9 * (si - 1);
      }
      if (third) ret += (long long int)9 * (ti - 1) + third;
      break;
  }
  printf("%lld\n", ret);
  return 0;
}
