#include <bits/stdc++.h>
using namespace std;
int facto(int k, int n) {
  int res = 1;
  for (int i = 0; i < n; i++) {
    res *= k;
  }
  return res;
}
int calc(int dig, int k) {
  if (k == 0) {
    return 1;
  }
  if (k < 0) {
    return 0;
  }
  int devidend = 1;
  int devisor = 1;
  for (int i = 0; i < k; i++) {
    devidend *= (dig - i);
    devisor *= i + 1;
  }
  return devidend / devisor;
}
int main() {
  string n;
  int k;
  cin >> n;
  cin >> k;
  int dig = n.length();
  int res = 0;
  for (int i = 0; i < dig - 1; i++) {
    int h = stoi(n.substr(i, 1));
    res += calc(dig - i - 1, k - i) * facto(9, k - i);
    res += (h - 1) * calc(dig - i - 1, k - 1 - i) * facto(9, k - 1 - i);
  }
  if (dig == k) {
    int h = stoi(n.substr(dig - 1, 1));
    res += h;
  }
  cout << res << endl;
  return 0;
}
