#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int64_t digit = s.size();
  int first;
  int second;
  int third;
  int k;
  cin >> k;
  if (k == 1) {
    cout << (s.size() - 1) * 9 + (int)(s.at(0)) - 48 << endl;
  } else if (k == 2) {
    first = (int)(s.at(0)) - 48;
    second = (int)(s.at(1)) - 48;
    if (digit < 2) {
      cout << 0 << endl;
    } else if (digit == 2) {
      cout << (first - 1) * 9 + second << endl;
    } else {
      cout << (digit - 1) * (digit - 2) / 2 * 81 +
                  (first - 1) * 9 * (digit - 1) + second + 9 * (digit - 2)
           << endl;
    }
  } else {
    if (digit < 3) {
      cout << 0 << endl;
    } else if (digit == 3) {
      first = (int)(s.at(0)) - 48;
      second = (int)(s.at(1)) - 48;
      third = (int)(s.at(2)) - 48;
      cout << (first - 1) * 81 + (second - 1) * 9 + third << endl;
    } else {
      first = (int)(s.at(0)) - 48;
      second = (int)(s.at(1)) - 48;
      third = (int)(s.at(2)) - 48;
      cout << (digit - 1) * (digit - 2) * (digit - 3) / 6 * 9 * 9 * 9 +
                  (first - 1) * (digit - 1) * (digit - 2) * 9 * 9 / 2 +
                  (second - 1) * 9 * (digit - 2) + (second) + 9 * (digit - 3)
           << endl;
    }
  }
}
