#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
using namespace std;
string n;
long long k;
long long check(long long x, long long y) {
  if (x < y) return 0;
  long long re = 1;
  for (long long i = 1; i <= y; i++) re *= x - i + 1;
  for (long long i = 2; i <= y; i++) re /= i;
  for (long long i = 1; i <= y; i++) re *= 9;
  return re;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  long long l = n.size();
  long long ans = 0;
  for (long long i = 0; i < l; i++) {
    if (n[i] > '0') {
      ans = ans + check(l - i - 1, k);
      ans = ans + check(l - i - 1, k - 1) * (n[i] - '0' - 1);
      k--;
    }
    if (!k) break;
  }
  cout << ans + 1;
  return 0;
}
