#include <bits/stdc++.h>
using namespace std;
int main(void) {
  string N;
  int K;
  cin >> N >> K;
  int digit = N.length();
  int first, second = 0, third = 0, s_i, t_i;
  first = N[0] - '0';
  for (s_i = 1; s_i < digit; s_i++) {
    if (N[s_i] != '0') {
      second = N[s_i] - '0';
      break;
    }
  }
  for (t_i = s_i + 1; t_i < digit; ++t_i) {
    if (N[t_i] != '0') {
      third = N[t_i] - '0';
      break;
    }
  }
  long long ans = 0;
  if (K == 1) {
    ans += (digit - 1) * 9;
    ans += first;
  } else if (K == 2) {
    for (int i = 2; i <= digit - 1; i++) {
      ans += (i - 1) * 81;
    }
    ans += second;
    ans += (first - 1) * 9;
    if (s_i < digit) {
      ans += first * (digit - s_i - 1) * 9;
    }
  } else {
    for (int i = 3; i <= digit - 1; i++) {
      ans += ((i - 1) * (i - 2) / 2) * 729;
    }
    ans += third;
    if (t_i < digit) {
      ans += (digit - t_i - 1) * 9;
    }
    if (s_i < digit) {
      ans += (second - 1) * (digit - s_i - 1) * 9;
    }
    if (s_i < digit - 2) {
      ans += ((digit - s_i - 1) * (digit - s_i - 2) / 2) * 81;
    }
    ans += (first - 1) * ((digit - 1) * (digit - 2) / 2) * 81;
  }
  printf("%lld\n", ans);
  return 0;
}
