#include <bits/stdc++.h>
using namespace std;
long long com(long long N, long long K) {
  long long ret = 1;
  if (N >= K && K != 0) {
    for (long long(i) = 0; (i) < (K); ++(i)) ret *= (N - i);
    for (long long i = K; i > 0; --i) ret /= i;
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  long long k, ans = 0;
  cin >> k;
  long long len = s.length(), head = s[0] - '0';
  if (k == 1)
    ans = 9 * (len - 1) + head;
  else if (k == 2 && len > 1) {
    long long a = 0;
    for (long long i = 2; i < len; ++i) a += 9 * 9 * (i - 1);
    long long b = 0, head1 = s[1] - '0', len1 = len - 1;
    if (head1 == 0)
      for (long long i = 2; i < len; ++i) {
        long long tmp = s[i] - '0';
        if (tmp != 0) {
          len1 = len - i;
          head1 = tmp;
          break;
        }
      }
    if (head1 != 0) {
      b += (head - 1) * 9 * (len - 1);
      b += 9 * (len1 - 1);
      b += head1;
    }
    ans += a + b;
  } else if (k == 3 && len > 2) {
    long long a = 0;
    for (long long i = 3; i < len; ++i) a += 9 * 9 * 9 * com(i - 1, 2);
    long long b = 0, head1 = s[1] - '0', len1 = len - 1;
    if (head1 == 0)
      for (long long i = 2; i < len; ++i) {
        long long tmp = s[i] - '0';
        if (tmp != 0) {
          len1 = len - i;
          head1 = tmp;
          break;
        }
      }
    long long head2 = s[min(len - len1 + 1, len - 1)] - '0', len2 = len1 - 1;
    if (len1 == 1) head2 = 0, len2 = 0;
    if (len1 > 1 && head2 == 0)
      for (long long i = len - len1 + 1; i < len; ++i) {
        long long tmp = s[i] - '0';
        if (tmp != 0) {
          len2 = len - i;
          head2 = tmp;
          break;
        }
      }
    if (head1 * head2 != 0) {
      b += (head - 1) * 9 * 9 * com(len - 1, 2);
      b += head2 * 9 * (len2 - 1);
      if (len1 - len2 - 1 >= 0) b += head2 * 9 * (len1 - len2 - 1);
      b += head1 * 9 * (len2 - 1);
      if (len1 - len2 - 1 >= 0) b += head1 * 9 * (len1 - len2 - 1);
      if (len1 > 3) b += 9 * 9 * com(len1 - 2, 2);
      b += head1 * head2;
    }
    if (head1 != 0 && head2 == 0 && len1 > 2) {
      b += (head - 1) * 9 * 9 * com(len - 1, 2);
      b += 9 * 9 * com(len1 - 1, 2);
      b += head1 * 9 * (len1 - 1);
    }
    ans += a + b;
  }
  cout << (ans) << endl;
  return 0;
}
