#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int k;
  string n;
  cin >> n >> k;
  ll ans = 0;
  vector<int> v(n.size());
  for (int i = 0; i < k; i++) v[i] = 1;
  sort(v.begin(), v.end());
  do {
    ll temp = 1;
    ll free = 0;
    for (int i = 0; i < n.size(); i++) {
      if (v[i]) {
        if (n[i] == '0') {
          free = free * 9;
          temp = 0;
        } else {
          free = free * 9 + (n[i] - '1') * temp;
        }
      } else {
        free = free + temp;
        temp = 0;
      }
    }
    ans += temp + free;
  } while (next_permutation(v.begin(), v.end()));
  cout << ans << endl;
  return 0;
}
