#include <bits/stdc++.h>
using namespace std;
int main() {
  string N;
  int K;
  cin >> N >> K;
  int digit = N.size();
  long ans = 0;
  if (K > digit) {
    ans = 0;
  } else {
    if (K == 1) {
      ans = (digit - 1) * 9 + (N[0] - '0');
    }
    if (K == 2) {
      ans = ((digit - 1) * (digit - 2) / 2) * 9 * 9 +
            (N[0] - '0' - 1) * (digit - 1) * 9 + (N[1] - '0') + (digit - 2) * 9;
    }
    if (K == 3) {
      ans = ((digit - 1) * (digit - 2) * (digit - 3) / 6) * 9 * 9 * 9 +
            (N[0] - '0' - 1) * (digit - 1) * (digit - 2) / 2 * 9 * 9 +
            (N[1] - '0' - 1) * (digit - 2) * 9 + (N[2] - '0') + (digit - 3) * 9;
      ;
    }
  }
  cout << ans << endl;
}
