#include <bits/stdc++.h>
using namespace std;
long long count(string N, int K) {
  long long n = N.length();
  long long n10 = (long long)(pow(10, n - 1));
  string tmp = N.substr(0, 1);
  long long nmax = stoi(tmp);
  switch (K) {
    case 1:
      if (n == 1) {
        return stoi(N);
      } else {
        return (long long)(nmax + count(to_string(n10 - 1), 1));
      }
      break;
    case 2:
      if (n == 1) {
        return 0;
      } else if (n == 2) {
        tmp = N.substr(1, 1);
        return (long long)(nmax - 1) * 9 + stoi(tmp);
      } else {
        return count(to_string(n10 - 1), 2) +
               (nmax - 1) * count(to_string(n10 - 1), 1) +
               count(N.substr(1, n - 1), 1);
      }
      break;
    case 3:
      if (n == 1) {
        return 0;
      } else if (n == 2) {
        return 0;
      } else if (n == 3) {
        return count(to_string(99), 2) * (nmax - 1) + count(N.substr(1, 2), 2);
      } else {
        return count(to_string(n10 - 1), 3) +
               (nmax - 1) * count(to_string(n10 - 1), 2) +
               count(N.substr(1, n - 1), 2);
      }
      break;
  }
}
signed main() {
  long long K;
  string N;
  cin >> N;
  cin >> K;
  cout << count(N, K);
  cout << endl;
}
