#include <bits/stdc++.h>
using namespace std;
const int QA[4] = {0, 9, 9 * 9, 9 * 9 * 9};
int main() {
  string n;
  int k;
  cin.sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> k;
  long long len = n.length();
  long long ulen = len - 1;
  long long uans = 0;
  long long sans = 0;
  if (k > len) {
    cout << 0 << endl;
    return 0;
  }
  switch (k) {
    case 1:
      uans = ulen * 9;
      sans = n[0] - '0';
      break;
    case 2:
      uans = (long long)ulen * (ulen - 1) / 2 * (9 * 9);
      sans = (long long)(ulen - 1) * (n[0] - '0') * 9 + (n[0] - '0' - 1) * 9 +
             (n[1] - '0');
      break;
    case 3:
      uans = (long long)ulen * (ulen - 1) * (ulen - 2) / 6 * (9 * 9 * 9);
      sans = (ulen > 3 ? (long long)(ulen - 2) * (ulen - 3) / 2 * (n[0] - '0') *
                             (9 * 9)
                       : 0) +
             (long long)(ulen - 2) * ((n[0] - '0' - 1) * 9 + (n[1] - '0')) * 9 +
             (n[0] - '0' - 1) * (9 * 9) +
             ((n[1] > '0') ? (n[1] - '0' - 1) * 9 + (n[2] - '0') : 0) +
             (long long)(ulen - 2) * 9 * 9 * (n[0] - '0');
      break;
  }
  cout << uans + sans << endl;
  return 0;
}
