#include <bits/stdc++.h>
using namespace std;
int combi(int n, int m) {
  if (m > n - m) m = n - m;
  if (m == 0 || n == m) return 1;
  return combi(n - 1, m) + combi(n - 1, m - 1);
}
int combination(int n, int m) {
  if (n < 1 || m < 0 || n < m) return 0;
  return combi(n, m);
}
int calc1(int n, int m) {
  if (n == 0 && m == 0) return 1;
  return combination(n, m) * pow(9, m);
}
void recrusive(vector<int> &vec, int k, int &count) {
  if (k == 0) {
    count += 1;
    return;
  }
  int vecSize = vec.size();
  int maxBit = vec[vecSize - 1];
  count += calc1(vecSize - 1, k);
  count += (maxBit - 1) * calc1(vecSize - 1, k - 1);
  vec.pop_back();
  recrusive(vec, k - 1, count);
}
int main() {
  string n;
  int k;
  cin >> n >> k;
  int nLen = (int)n.length();
  const char *c = n.c_str();
  vector<int> vec = {};
  for (int i = 0; i < nLen; i++) {
    int ni = c[nLen - 1 - i] - '0';
    vec.push_back(ni);
  }
  int count = 0;
  recrusive(vec, k, count);
  cout << count << endl;
  return 0;
}
