#include <bits/stdc++.h>
int one(int N[], int Longth);
int two(int N[], int Longth);
int three(int N[], int Longth);
int main(void) {
  char N[100];
  int K;
  scanf("%s", N);
  scanf("%d", &K);
  int Nint[strlen(N)];
  for (int i = 0; i < strlen(N); i++) {
    Nint[i] = N[i] - '0';
  }
  int counting = 0;
  if (K == 1) {
    counting += one(Nint, strlen(N));
  }
  if (K == 2) {
    counting += two(Nint, strlen(N));
  }
  if (K == 3) {
    counting += three(Nint, strlen(N));
  }
  printf("%d", counting);
}
int one(int N[], int Longth) {
  int m = 0;
  for (int i = 1; i < Longth; i++) {
    m += 9;
  }
  return m + N[0];
}
int two(int N[], int Longth) {
  int m = 0;
  for (int i = 1; i < Longth - 1; i++) {
    m += 81 * i;
  }
  for (int i = 0; i < N[0]; i++) {
    m += 9 * (Longth - 1);
  }
  return m + N[1] - 9;
}
int three(int N[], int Longth) {
  int m = 0;
  for (int i = 2; i < Longth - 1; i++) {
    m += 729 * i * (i - 1) / 2;
  }
  for (int i = 0; i < N[0] - 1; i++) {
    m += 81 * (Longth - 1) * (Longth - 2) / 2;
  }
  for (int i = 0; i < N[1] - 1; i++) {
    m += 9 * (Longth - 2);
  }
  return m + N[2];
}
