#include <bits/stdc++.h>
using namespace std;
int cb(int n, int k) {
  if (n < k) return 0;
  if (k == 0) {
    return 1;
  } else if (k == 1) {
    return n;
  } else if (k == 2) {
    return n * (n - 1) / 2;
  } else {
    return n * (n - 1) * (n - 2) / 6;
  }
}
int nine(int k) {
  int ans = 1;
  if (k < 0)
    return 0;
  else {
    for (int i = 0; (i) < (k); (i)++) ans *= 9;
    return ans;
  }
}
int main() {
  string Nmoji, temp;
  int N, K, nk, nkm, index;
  long ans;
  cin >> Nmoji;
  cin >> K;
  ans = 0;
  nk = 1;
  for (int i = 0; (i) < (K); (i)++) nk *= 9;
  nkm = 1;
  for (int i = 0; (i) < (K - 1); (i)++) nkm *= 9;
  N = Nmoji.length();
  index = 0;
  for (int i = 0; (i) < (N - K + 1); (i)++) {
    if (index == K) {
      ans += 1;
      break;
    }
    if (Nmoji[i] == '0') continue;
    ans += cb(N - 1 - i, K - index) * nine(K - index) +
           cb(N - 1 - i, K - 1 - index) * nine(K - index - 1) *
               ((int)(Nmoji[i] - '0') - 1);
    index++;
  }
  if (K == 2 && index == 1) ans += (int)(Nmoji[N - 1] - '0');
  if (K == 3 && index == 1)
    if (Nmoji[N - 2] != '0')
      ans += (int)(Nmoji[N - 1] - '0') + ((int)(Nmoji[N - 2] - '0') - 1) * 9;
  if (K == 3 && index == 2)
    if (Nmoji[N - 2] == '0')
      ans += (int)(Nmoji[N - 1] - '0');
    else
      ans += (int)(Nmoji[N - 1] - '0') + ((int)(Nmoji[N - 2] - '0') - 1) * 9;
  cout << ans << endl;
  return 0;
}
