#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
}
int main() {
  string n;
  cin >> n;
  int k;
  cin >> k;
  long long ans = 0;
  int already_use = 0;
  for (long long i = 0; i < (long long)(n.size()); ++i) {
    for (long long j = 0; j < (long long)(n[i] - '0'); ++j) {
      int already_use2 = already_use;
      if (j > 0) already_use2++;
      int select_num = k - already_use2;
      long long tmp_cross = 1;
      for (long long k = 0; k < (long long)(select_num); ++k) {
        tmp_cross *= n.size() - i - 1 - k;
      }
      long long tmp_div = 1;
      for (long long k = 0; k < (long long)(select_num); ++k) {
        tmp_div *= select_num - k;
      }
      long long tmp = tmp_cross / tmp_div;
      ans += tmp * pow(9, select_num);
    }
    already_use++;
    if (already_use >= k) {
      if (n[i] - '0' != 0) ans++;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
