#include <bits/stdc++.h>
using namespace std;
long nine[4] = {1L, 9L, 81L, 729L};
long comb(long a, long b) {
  long out = 1;
  for (long i = 0; i < b; ++i) out *= a - i;
  for (long i = 0; i < b; ++i) out /= i + 1;
  return out;
}
long count(long n[], long l, long k) {
  if (k == 1) {
    return n[0] + 9 * (l - 1);
  } else {
    long ans = 0;
    ans += (l == 1) ? 0 : count(n + 1, l - 1, k - 1);
    ans += (n[0] - 1) * comb(l - 1, k - 1) * nine[k - 1];
    ans += comb(l - 1, k) * nine[k];
    return ans;
  }
}
string s;
long n[101];
long k, l, ans;
int main() {
  cin >> s >> k;
  l = s.size();
  for (int i = 0; i < l; ++i) n[i] = s[i] - '0';
  cout << count(n, l, k);
  return 0;
}
