#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  long long n = s.size();
  long long k;
  cin >> k;
  int a[3];
  for (int i = int(0); i < int(k); i++) a[i] = s[i] - '0';
  long long an;
  if (k == 1) {
    an = a[0] + (n - 1) * 9;
  } else if (k == 2) {
    an = a[1] + (n - 2) * 9 + (a[0] - 1) * (n - 1) * 9 +
         (n - 1) * (n - 2) / 2 * 81;
  } else {
    an = a[2] + (n - 3) * 9 + max(0, (a[1] - 1)) * (n - 2) * 9 +
         (n - 2) * (n - 3) / 2 * 81 + (a[0] - 1) * (n - 1) * (n - 2) / 2 * 81 +
         (n - 1) * (n - 2) * (n - 3) / 6 * 729;
  }
  cout << an << endl;
}
