#include <bits/stdc++.h>
using namespace std;
__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
int main(void) {
  string S;
  int K;
  cin >> S;
  cin >> K;
  long long int ans = 0;
  int N = S.size();
  vector<int> s;
  for (int i = N - 1; i >= 0; i--) {
    s.push_back(S[i] - '0');
  }
  long long int a[K];
  long long int c = 0;
  long long int c3 = 0;
  long long int q = 1;
  a[0] = 0;
  a[1] = 0;
  if (N >= K) {
    for (int i = 0; i < (int)(N); i++) {
      if (i > 1) c += i - 1;
      if (i > 3) {
        c3 *= i;
        c3 /= (i - 3);
      }
      a[2] = c3 * 9 * 9 * 9 + (s[i] - 1) * 81 * c + a[1];
      a[1] = 81 * c + (s[i] - 1) * 9 * i + a[0];
      a[0] = s[i] + i * 9;
      if (i == 2) c3 = 1;
      ans = a[K - 1];
    }
  } else {
    ans = 0;
  }
  cout << ans << endl;
  return 0;
}
