#include <bits/stdc++.h>
using namespace std;
const long long N = 2e6 + 5;
const long long INF = 1e18L;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
long long ar[N];
long long dp[N];
long long pow1(long long x, long long y) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) {
      ans *= x;
    }
    x *= x;
    y >>= 1;
  }
  return ans;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  ;
  long long T = 1;
  while (T--) {
    string s;
    cin >> s;
    long long k;
    cin >> k;
    if (k == 1) {
      long long q = s.size() - 1, ans = 0;
      ans += 9 * q;
      ans += (long long)(s[0] - '0') - 1;
      ans += 1ll;
      return cout << ans, 0;
    }
    long long n = s.size();
    string t(n - 1, '0');
    for (long long i = 0; i < k - 1; i++) t[n - 2 - i] = '1';
    long long cnt = 0;
    vector<long long> C;
    for (long long i = pow1(10ll, k - 1) + 1; i < pow1(10ll, k); i++) {
      long long ii = i;
      long long flag = 1;
      while (ii) {
        if ((ii % 10) == 0) flag = 0;
        ii /= 10;
      }
      if (flag) cnt++;
      if (flag) C.push_back(i);
    }
    long long mul = 1, den = 1;
    for (long long i = 0; i < k; i++) {
      mul *= (n - 1 - i);
      den *= (i + 1);
    }
    long long ans = 1ll * (mul / den) * cnt;
    do {
      vector<long long> p;
      p.push_back(0);
      for (long long i = 0; i < n - 1; i++)
        if (t[i] == '1') p.push_back(i + 1);
      string t1 = "1";
      t1 += t;
      vector<long long> d(k);
      for (long long i : C) {
        long long ii = i;
        for (long long j = 0; ii > 0 && j < k; j++) {
          d[k - 1 - j] = ii % 10;
          ii /= 10;
        }
        for (long long j = 0; j < k; j++) {
          if (t1.size() <= p[j]) continue;
          t1[min((long long)(t1.size() - 1), p[j])] = '0' + d[j];
        }
        if (t1 <= s) ans++;
      }
    } while (next_permutation(t.begin(), t.end()));
    cout << ans;
  }
  cerr << "Time Taken : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
  return 0;
}
