#include <bits/stdc++.h>
using namespace std;
int dp[1000] = {};
int count(string num) {
  if (dp[stoi(num)] != 0) return dp[stoi(num)];
  int ans = 0;
  string s(num.size(), '1');
  for (int n = stoi(s); n <= stoi(num); n++) {
    if (to_string(n).find('0') == string::npos) ans++;
  }
  return dp[stoi(num)] = ans;
}
int main() {
  string N;
  cin >> N;
  int K;
  cin >> K;
  string S(N.size(), '0');
  for (int i = 0; i < K; i++) S[S.size() - 1 - i] = '1';
  long long ans = 0;
  string prev;
  while (1) {
    string num = "";
    if (S[0] == '1') {
      num += N[0];
      bool a = true;
      for (int i = 1; i < N.size(); i++) {
        if (S[i] == '1') {
          if (a)
            num += N[i];
          else
            num += '9';
        } else if (N[i] != '0') {
          a = false;
        }
      }
    } else {
      for (int i = 0; i < K; i++) num += '9';
    }
    ans += count(num);
    prev = S;
    next_permutation(S.begin(), S.end());
    if (prev >= S) break;
  }
  cout << ans << endl;
  return 0;
}
