#include <bits/stdc++.h>
using namespace std;
string N;
long long K;
long long ans = 0;
long long choice(long long N, long long r) {
  long long ret = 1;
  for (long long i = 0; i < r; i++) ret *= N - i;
  for (long long i = 0; i < r; i++) ret /= i + 1;
  for (long long i = 0; i < r; i++) ret *= 9;
  return max(0LL, ret);
}
long long f(long long digit, long long select, bool smaller) {
  if ((long long)N.length() - digit < K - select) return 0;
  if (select == K) return 1;
  if (smaller) {
    return choice(N.length() - digit, K - select);
  }
  long long ret = 0;
  if (N[digit] != '0') ret += f(digit + 1, select, true);
  if (N[digit] >= '2')
    ret += max(0LL, f(digit + 1, select + 1, true) * (N[digit] - '0' - 1));
  if (N[digit] >= '1') ret += f(digit + 1, select + 1, false);
  return ret;
}
signed main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N;
  cin >> K;
  long long len = N.length();
  long long ans = 0;
  cout << f(0, 0, false) << endl;
  return 0;
}
