#include <bits/stdc++.h>
using namespace std;
long long ctol(char c) {
  switch (c) {
    case '0':
      return 0;
    case '1':
      return 1;
    case '2':
      return 2;
    case '3':
      return 3;
    case '4':
      return 4;
    case '5':
      return 5;
    case '6':
      return 6;
    case '7':
      return 7;
    case '8':
      return 8;
    case '9':
      return 9;
    default:
      return 0;
  }
}
long long nCr(long long n, long long r) {
  long long ans = 1;
  for (long long i = n; i > n - r; --i) {
    ans = ans * i;
  }
  for (long long i = 1; i < r + 1; ++i) {
    ans = ans / i;
  }
  return ans;
}
long long k1(string n_s) {
  long long n = n_s.length();
  long long top = ctol(n_s[0]);
  return (n * 9 - (9 - top));
}
string cut0(string input) {
  string ret;
  for (int i = 0; i < (input.length()); ++i) {
    if (input[i] != '0') {
      ret += input[i];
    }
  }
  return ret;
}
long long k2(string n_s) {
  long long n = n_s.length();
  long long top = ctol(n_s[0]);
  if (n == 1) {
    return 0;
  }
  long long ans = 0;
  string tmp = n_s;
  tmp.erase(0, 1);
  string rest_top = cut0(tmp);
  ans += (top - 1) * (n - 1) * 9;
  if (n >= 3) {
    ans += nCr(n - 1, 2) * 81;
  }
  ans += k1(rest_top);
  if (ans <= 0) {
    return 0;
  }
  return ans;
}
int main() {
  string n_s;
  cin >> n_s;
  long long k;
  long long n = n_s.length();
  long long top = ctol(n_s[0]);
  cin >> k;
  if (k == 1) {
    cout << k1(n_s) << endl;
    return 0;
  }
  if (k == 2) {
    cout << k2(n_s) << endl;
    return 0;
  }
  if (k == 3) {
    if (k <= 2) {
      cout << 0 << endl;
      return 0;
    }
    long long ans = 0;
    string tmp = n_s;
    tmp.erase(0, 1);
    string rest_top = cut0(tmp);
    if (top >= 2) {
      ans += (top - 1) * nCr(n - 1, 2) * 81;
    }
    if (n >= 4) {
      ans += nCr(n - 1, 3) * 9 * 9 * 9;
    }
    ans += k2(rest_top);
    if (ans <= 0) {
      cout << 0 << endl;
      return 0;
    }
    cout << ans << endl;
  }
  return 0;
}
