#include <bits/stdc++.h>
using namespace std;
int main() {
  long long r = 0;
  string N;
  int nl, K;
  cin >> N >> K;
  nl = N.size();
  if (K == 1) {
    r += N.at(0) - '0';
    r += 9 * (nl - 1);
  } else if (K == 2) {
    if (nl < K) {
      cout << 0 << endl;
      return 0;
    }
    r += 9 * 9 * (nl - 1) * (nl - 2) / 2;
    r += (N.at(0) - '1') * (nl - 1) * 9;
    r += N.at(1) - '0';
    r += 9 * (nl - 2);
  } else {
    if (nl < K) {
      cout << 0 << endl;
      return 0;
    }
  }
  cout << r << endl;
}
