#include <bits/stdc++.h>
using namespace std;
int main() {
  string N;
  int K;
  cin >> N;
  cin >> K;
  size_t size = N.length();
  char a, b, c;
  a = N.at(0);
  b = N.at(1);
  c = N.at(2);
  int A, B, C;
  int ans;
  A = a - '0';
  B = b - '0';
  C = c - '0';
  if (K == 1) {
    ans = 9 * (size - 1) + A;
  } else if (K == 2) {
    ans = 81 * (size - 1) * (size - 2) / 2 + (A - 1) * (size - 1) * 9 +
          1 * (9 * (size - 2) + B);
  } else if (K == 3) {
    ans = 719 * (size - 1) * (size - 2) * (size - 3) / 6 +
          (A - 1) * (81 * (size - 2) * (size - 3) / 2 +
                     (B - 1) * (size - 2) * 9 + 1 * (9 * (size - 3) + C)) +
          1 * 1 * 9 * (size - 3) + C;
  }
  cout << ans << endl;
}
