#include <bits/stdc++.h>
using namespace std;
const long long LINF = 1e18;
const int INF = 1e9;
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
using Graph = vector<vector<long long>>;
const long long MOD = 1000000007;
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(15);
  string s;
  cin >> s;
  long long k;
  cin >> k;
  long long ans = 0;
  if (k > s.size()) {
    cout << 0 << endl;
    return 0;
  }
  if (k == 1) {
    ans += (long long)(s[0] - '0');
    ans += (long long)(9 * (s.size() - 1));
  } else if (k == 2) {
    ans += s[1] - '0';
    ans += (s.size() - 2) * 9;
    ans += (s[0] - '0' - 1) * (s.size() - 1) * 9;
    for (int i = 1; i < s.size() - 1; i++) {
      for (int j = i + 1; j < s.size(); j++) {
        ans += 9 * 9;
      }
    }
  } else {
    ans += (long long)(s[2] - '0');
    if (s[1] != '0') ans += (long long)((s.size() - 3) * 9);
    if (s[1] != '0')
      ans += (long long)((long long)(s[1] - '0' - 1) * (s.size() - 2) * 9);
    ans += (long long)((((s[0] - '0' - 1) * (s.size() - 1) * (s.size() - 2)) *
                        9 * 9) /
                       2);
    if (s[1] != '0')
      ans += (long long)((s.size() - 2) * (s.size() - 3) * 9 * 9) / 2;
    for (int i = 1; i < s.size() - 2; i++) {
      for (int j = i + 1; j < s.size() - 1; j++) {
        for (int k = j + 1; k < s.size(); k++) {
          ans += 9 * 9 * 9;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
