#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int k;
  cin >> s >> k;
  long long ans = 0, cnt = 0;
  for (int i = 0; i < s.length() && k > 0; i++) {
    if (s[i] != 0) {
      long long plus = 1;
      for (int j = 0; j < k; j++) {
        plus *= 9 * (s.length() - i - 1 - j);
      }
      for (int j = 0; j < k; j++) {
        plus /= j + 1;
      }
      ans += plus;
      plus = 1;
      for (int j = 0; j < k - 1; j++) {
        plus *= 9 * (s.length() - i - 1 - j);
      }
      for (int j = 0; j < k - 1; j++) {
        plus /= j + 1;
      }
      ans += (s[i] - '0' - 1) * plus;
      k--;
    }
  }
  cout << ans + 1 << endl;
}
