#include <bits/stdc++.h>
using namespace std;
int main() {
  string N;
  int64_t res = 0;
  int K, top, l, nxt, trd;
  cin >> N >> K;
  top = N.at(0) - '0';
  l = N.size();
  if (K == 1) {
    res = top + 9 * (l - 1);
    cout << res << endl;
    return 0;
  }
  if (K == 2) {
    if (l == 1) {
      cout << 0 << endl;
      return 0;
    }
    if (l == 2) {
      res += (top - 1) * 9;
      res += N.at(1) - '0';
      cout << res << endl;
      return 0;
    }
    res += ((l - 1) * (l - 2) / 2) * 9 * 9;
    res += (top - 1) * (l - 1) * 9;
    res += N.at(1) - '0';
    res += (l - 2) * 9;
    cout << res << endl;
    return 0;
  }
  if (l <= 2) {
    cout << 0 << endl;
    return 0;
  }
  if (l == 3) {
    nxt = N.at(1) - '0';
    trd = N.at(2) - '0';
    res += (top - 1) * 9 * 9;
    res += (nxt - 1) * 9;
    res += trd;
    cout << res << endl;
    return 0;
  }
  res += ((l - 1) * (l - 2) * (l - 3) / 6) * 9 * 9 * 9;
  res += (top - 1) * ((l - 1) * (l - 2) / 2) * 9 * 9;
  nxt = N.at(1) - '0';
  trd = N.at(2) - '0';
  res += ((l - 2) * (l - 3) / 2) * 9 * 9;
  res += (nxt - 1) * (l - 2) * 9;
  res += (l - 3) * 9;
  res += trd;
  cout << res << endl;
}
