#include <bits/stdc++.h>
using namespace std;
long long C(long long n, long long r) {
  cerr << n << " " << r << endl;
  if (n < r || r <= 0 || n <= 0) {
    cerr << "a" << endl;
    return (long long)0;
  }
  long long up = 1;
  long long down = 1;
  long long max_v = max(r, n - r);
  long long min_v = min(r, n - r);
  for (long long i = n; i > max_v; i--) {
    up *= i;
  }
  for (long long i = 1; i <= min_v; i++) {
    down *= i;
  }
  cerr << up / down << endl;
  return up / down;
}
int main() {
  long long K;
  string N;
  cin >> N >> K;
  long long ans = 0;
  long long nonzero = 0;
  long long num;
  for (int i = 0; i < N.size(); i++) {
    num = N.size() - i;
    ans += C(num - 1, K - nonzero) * pow(9, K - nonzero);
    ans += C(num - 1, K - 1 - nonzero) * pow(9, K - 1 - nonzero) *
           (atoi(N.substr(i, 1).c_str()) - 1);
    ans += 1 * (long long)(nonzero + 1 == K) * (atoi(N.substr(i, 1).c_str()));
    if (N[i] != '0') nonzero++;
    if (nonzero >= K) break;
    cerr << ans << endl;
  }
  cout << ans << endl;
  return 0;
}
