#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
bool inc(vector<int>& ris, int n, int d = 0) {
  if (ris[d] + 1 >= n) return false;
  if (d != ris.size() - 1 && ris[d] + 1 == ris[d + 1]) {
    return inc(ris, n, d + 1);
  } else {
    ris[d]++;
    for (int i = 0; i < (d); ++i) ris[i] = i;
    return true;
  }
}
int po(int a, int b) {
  int c = 1;
  for (int i = 0; i < (b); ++i) c *= a;
  return c;
}
int main() {
  string s;
  int k;
  cin >> s >> k;
  int n = s.size();
  if (n < k) {
    cout << 0 << endl;
    return 0;
  }
  reverse(s.begin(), s.end());
  vector<int> nis, ris(k);
  for (int i = n - 1; i >= 0; i--)
    if (s[i] != '0') nis.push_back(i);
  reverse(nis.begin(), nis.end());
  for (int i = 0; i < (k); ++i) ris[i] = i;
  ll cnt = 0;
  while (1) {
    bool br = false;
    for (int i = 0; i < (k); ++i) {
      int ni = nis.size() - 1 - i, ri = ris.size() - 1 - i;
      if (ni < 0 || nis[ni] < ris[ri]) {
        br = true;
        break;
      } else if (nis[ni] > ris[ri])
        break;
    }
    for (int i = 0; i < (k); ++i) {
      int ni = nis.size() - 1 - i, ri = ris.size() - 1 - i;
      if (nis[ni] > ris[ri]) {
        cnt += po(9, k - i);
        break;
      } else {
        int a = s[nis[ni]] - '0';
        cnt += (a - 1) * po(9, k - i - 1);
        if (i == k - 1) cnt++;
      }
    }
    if (br) break;
    if (!inc(ris, n)) break;
  }
  cout << cnt << endl;
  return 0;
}
