#include <bits/stdc++.h>
using namespace std;
char s[200];
long long n[200];
int main(void) {
  scanf("%s", s);
  for (long long i = 0; i < strlen(s); i++) {
    n[i] = s[i] - '0';
  }
  long long k, sum = 0, l = strlen(s);
  scanf("%lld", &k);
  if (k == 1) {
    sum += (l - 1) * 9;
    sum += n[0];
  } else if (k == 2 && l > 1) {
    for (long long i = 2; i <= l - 1; i++) {
      sum += 9 * 9 * (i - 1);
    }
    sum += (n[0] - 1) * (l - 1) * 9;
    long long i1 = -1;
    for (long long i = 1; i < l; i++) {
      if (n[i] != 0) {
        i1 = i;
        break;
      }
    }
    long long n1[200];
    for (long long i = i1; i < l; i++) {
      n1[i - i1] = n[i];
    }
    l = l - i1;
    sum += (l - 1) * 9;
    sum += n1[0];
  } else if (k == 3 && l > 2) {
    for (int i = 2; i <= l - 1; i++) {
      sum += 9 * 9 * 9 * (((i - 1) * (i - 2)) / 2);
    }
    sum += 9 * 9 * (n[0] - 1) * (((l - 1) * (l - 2)) / 2);
    int i1 = -1, i2 = -1;
    for (int i = 0; i < l; i++) {
      if (n[i] != 0) {
        if (i1 == -1) {
          i1 = i;
        }
      }
    }
    int n2[200];
    if (i1 < l - 1) {
      for (long long i = i1; i < l; i++) {
        n2[i - i1] = n[i];
      }
      l = l - i1;
      for (long long i = 2; i <= l - 1; i++) {
        sum += 9 * 9 * (i - 1);
      }
      sum += (n2[0] - 1) * (l - 1) * 9;
      long long i2 = -1;
      for (long long i = 1; i < l; i++) {
        if (n2[i] != 0) {
          i2 = i;
          break;
        }
      }
      long long n1[200];
      for (long long i = i2; i < l; i++) {
        n1[i - i2] = n2[i];
      }
      l = l - i2;
      sum += (l - 1) * 9;
      sum += n1[0];
    }
  }
  printf("%lld", sum);
}
