#include <bits/stdc++.h>
using namespace std;
long long ctoll(char a) { return (long long)a - '0'; }
long long calcC(long long a, long long b) {
  long long r = 1;
  for (int i = 0; i < (b); i++) {
    r *= (a - i);
  }
  for (int i = 0; i < (b); i++) {
    r /= (i + 1);
  }
  return r;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  long long K;
  cin >> K;
  long long l = S.length();
  if (l < K) {
    cout << 0 << "\n";
    return 0;
  }
  long long pow9[4] = {1, 9, 9 * 9, 9 * 9 * 9};
  long long ans = 0;
  if (l > K) {
    ans += calcC(l - 1, K) * pow9[K];
  }
  long long max_n = ctoll(S[0]);
  if (K == 1) {
    ans += max_n;
  } else {
    long long second_n = ctoll(S[1]);
    if (K == 2) {
      ans += (max_n - 1) * (l - 1) * 9 + second_n + (l - 2) * 9;
    } else {
      long long third_n = ctoll(S[2]);
      ans += (max_n - 1) * calcC(l - 1, 2) * pow9[2] +
             calcC(l - 2, 2) * pow9[2] + (second_n - 1) * (l - 2) * 9 +
             third_n + (l - 3) * 9;
    }
  }
  cout << ans << "\n";
  return 0;
}
