#include <bits/stdc++.h>
using namespace std;
uintmax_t combination(unsigned int n, unsigned int r) {
  if (r * 2 > n) r = n - r;
  uintmax_t dividend = 1;
  uintmax_t divisor = 1;
  for (unsigned int i = 1; i <= r; ++i) {
    dividend *= (n - i + 1);
    divisor *= i;
  }
  return dividend / divisor;
}
long long int dpow(long long int x, long long int n) {
  long long int t = 1;
  for (long long int i = 0; i < n; i++) {
    t *= x;
  }
  return t;
}
int main(int argc, char const *argv[]) {
  string s;
  cin >> s;
  long long int n, k;
  cin >> k;
  n = s.size();
  if (n == 1) {
    n = s[0] - '0';
    if (k == 1) {
      cout << n << endl;
    } else {
      cout << 0 << endl;
    }
    exit(0);
  }
  long long int ans = 0;
  if (k == 1) ans = 9;
  long long int temp = 10;
  long long int keta = 2;
  while (keta < n) {
    ans += 9 * dpow(9, k - 1) * combination(keta - 1, k - 1);
    keta++;
    temp *= 10;
  }
  if (k == 1) {
    cout << ans + (s[0] - '0') << endl;
    exit(0);
  }
  long long int d = n / temp;
  ans += (d - 1) * dpow(9, k - 1) * combination(keta - 1, k - 1);
  cout << ans << endl;
}
