#include <bits/stdc++.h>
using namespace std;
int main() {
  string N;
  int K;
  cin >> N >> K;
  int L = N.length();
  if (L < K) {
    cout << 0 << endl;
    return 0;
  }
  int ans;
  switch (K) {
    case 1:
      ans = (N[0] - '0') + 9 * (L - 1);
      break;
    case 2:
      ans = (N[0] != '1' ? (N[0] - '0' - 1) * 9 : 0) + (N[1] - '0') +
            (L > 2 ? (N[0] - '0') * 9 * (L - 2) + (L - 1) * (L - 2) / 2 * 9 * 9
                   : 0);
      break;
    case 3:
      ans = (N[0] != '1' ? (N[0] - '0' - 1) * 9 * 9 : 0) +
            (N[1] != '1' ? (N[1] - '0' - 1) * 9 : 0) + (N[2] - '0') +
            (L > 3 ? ((N[0] != '1' ? (N[0] - '0' - 1) * 9 : 0) + (N[1] - '0')) *
                             9 * (L - 3) +
                         (N[0] - '0') * (L - 2) * (L - 3) / 2 * 9 * 9 +
                         (L - 1) * (L - 2) * (L - 3) / 6 * 9 * 9 * 9
                   : 0);
  }
  cout << ans << endl;
}
