#include <bits/stdc++.h>
using namespace std;
template <typename TYPE>
void print_vec(const vector<TYPE>& v) {
  for (int i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << endl;
}
template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v) {
  cout << endl;
  cout << "       ";
  for (int i = 0; i < v[0].size(); i++) cout << i << "   ";
  cout << endl;
  for (int i = 0; i < v.size(); i++) {
    cout << "i=" << i << ":   ";
    for (int j = 0; j < v[i].size(); j++) {
      if (v[i][j] == 0)
        cout << "\x1B[0m" << v[i][j] << "   ";
      else
        cout << "\x1B[31m" << v[i][j] << "   ";
    }
    cout << "\x1B[0m" << endl;
  }
}
int main() {
  string s;
  cin >> s;
  int K;
  cin >> K;
  int num_digit = s.size();
  int num_top = s[0] - '0';
  long long ans = 0;
  if (K == 1) {
    ans += (num_digit - 1) * 9;
    ans += num_top;
    cout << ans << endl;
    return 0;
  }
  if (K == 2) {
    long long n_1C2 = (num_digit - 1) * (num_digit - 2) / 2;
    ans += n_1C2 * 9 * 9;
    ans += (num_top - 1) * 9;
    for (int i = 1; i < num_digit; i++) {
      if (s[i] == '0') continue;
      ans += (s[i] - '0' - 1);
      ans += (num_digit - i) * 9;
      break;
    }
    cout << ans << endl;
    return 0;
  }
  long long n_1C3 = (num_digit - 1) * (num_digit - 2) * (num_digit - 3) / 3 / 2;
  ans += n_1C3 * 9 * 9 * 9;
  ans += (num_top - 1) * 9 * 9;
  for (int i = 1; i < num_digit; i++) {
    if (s[i] == '0') continue;
    ans += (num_digit - i) * 9 * 9;
    for (int j = i + 1; j < num_digit; j++) {
      if (s[j] == '0') continue;
      ans += (num_digit - j) * 9;
      ans += (s[i] - '0' - 1) * (num_digit - j);
      ans += 1 * (s[j] - '0' - 1) * 9;
    }
    break;
  }
}
