#include <bits/stdc++.h>
using namespace std;
string s;
long long n, k;
long long ans = 0;
void rec(long long pos, long long fl, long long cnt, long long c) {
  if (pos == n) {
    if (cnt == k) ans += c;
  } else {
    long long v = s[pos] - '0';
    if (cnt < k) {
      if (fl) {
        rec(pos + 1, fl, cnt + 1, c * 9);
      } else {
        rec(pos + 1, 1, cnt + 1, c * (v - 1));
        rec(pos + 1, 0, cnt + 1, c);
      }
    }
    rec(pos + 1, fl | (v > 0), cnt, c);
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> s >> k;
  n = (long long)s.size();
  rec(0, 0, 0, 1);
  cout << ans << endl;
}
