#include <bits/stdc++.h>
using namespace std;
int C[111][111];
int p9[5] = {1, 9, 81, 729, 6561};
int recursive(string N, int c, int k) {
  int ret = 0, d = N.size();
  if (c >= d - 1) return N[d - 1] - '0';
  if (k == 0) return 1;
  if (d - c < k) return 0;
  if (N[c] > '0') {
    ret += C[d - 1 - c][k] * p9[k];
    ret += (N[c] - '1') * C[d - 1 - c][k - 1] * p9[k - 1];
    ret += recursive(N, c + 1, k - 1);
  } else {
    ret += recursive(N, c + 1, k);
  }
  return ret;
}
int main() {
  int K;
  char c[111];
  scanf("%s %d", c, &K);
  string N(c);
  int d = N.size();
  C[0][0] = 1;
  for (int n = 0; n < 111; n += 1) C[n][0] = C[n][n] = 1;
  for (int n = 0; n < 110; n += 1)
    for (int k = 1; k < 111; k += 1) C[n + 1][k] = C[n][k - 1] + C[n][k];
  int ans = recursive(N, 0, K);
  printf("%d\n", ans);
  return 0;
}
