#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
void numberPlusOne(char* p, int index) {
  char ch1 = '\0';
  char* ptr = &ch1;
  int plus = 1;
  for (int i = index - 1; i >= 0; i--) {
    ch1 = p[i];
    int num = atoi(ptr);
    if (num + plus > 9) {
      plus = 1;
      p[i] = '0';
    } else {
      plus = 0;
      p[i] = 48 + ++num;
      break;
    }
  }
}
bool checkNonZero(char* p, int K) {
  int count = 0;
  for (int i = 0; i < 100; i++) {
    char ch = p[i];
    int digits = atoi(&ch);
    if (digits != 0) {
      count++;
    }
  }
  if (count == K)
    return true;
  else
    return false;
}
bool checkNumber(char* p1, char* p2) {
  int count = 0;
  for (int i = 0; i < 100; i++) {
    if (p1[i] == p2[i]) count++;
  }
  if (100 == count)
    return false;
  else
    return true;
}
void copytoLast(char* p) {
  int len = strlen(p);
  int j = 0;
  for (int i = len; i > 0; i--) {
    p[100 - i] = p[j];
    p[j] = '\0';
    j++;
  }
}
int main() {
  char N[100] = {
      0,
  };
  char N_temp[100] = {
      0,
  };
  int K = 0;
  scanf("%s", N);
  scanf("%d", &K);
  int index = strlen(N);
  int sum = 0;
  bool check = true;
  do {
    numberPlusOne(N_temp, index);
    if (checkNonZero(N_temp, K) == true) {
      sum++;
    }
    check = checkNumber(N, N_temp);
  } while (check);
  printf("sum = %d\n", sum);
  return 0;
}
