#include <bits/stdc++.h>
char str[200];
int n;
int dy0[200][10];
int dy1[200][10];
int d(int a, int b, int c) {
  if (a == 0) return 0;
  if (a == 1) return dy1[b][c];
  if (c > 0) {
    return d(1, b, c) + (a - 1) * dy0[b][c - 1];
  } else {
    return 0;
  }
}
int check(char *str) {
  int val = atoi(str);
  int cnt = 0;
  for (int i = 1; i <= val; i++) {
    char a[100];
    sprintf(a, "%d", i);
    int count = 0;
    for (int j = 0; j < strlen(a); j++) {
      if (a[j] != '0') count++;
    }
    if (count == n) cnt++;
  }
  return cnt;
}
int main(void) {
  int result = scanf("%s %d", str, &n);
  dy0[0][0] = 1;
  dy1[0][1]++;
  for (int i = 1; i <= 120; i++) {
    dy0[i][0] = 1;
    for (int j = 1; j <= 4; j++) {
      dy0[i][j] = dy0[i - 1][j] + 9 * dy0[i - 1][j - 1];
      dy1[i][j] = dy0[i][j];
    }
    dy1[i][1]++;
  }
  int len = strlen(str);
  int dap = 0;
  int n2 = n;
  for (int i = 0; i < len; i++) {
    dap += d(str[i] - '0', len - i - 1, n2);
    if (str[i] != '0') n2--;
  }
  printf("%d\n", dap);
  return 0;
}
