#include <bits/stdc++.h>
using namespace std;
long long Comb(long long a, long long b) {
  long long ret = 1;
  for (int i = 0; i < b; ++i) {
    ret *= a - i;
  }
  for (int i = b; i >= 1; --i) {
    ret /= i;
  }
  return ret;
}
int main() {
  string S;
  cin >> S;
  int K;
  cin >> K;
  int N = S.size();
  long long ans;
  if (K == 1) {
    ans = Comb(N, 1) * 9;
    ans -= (9 - int(S[0] - '0'));
  } else if (K == 2) {
    ans = Comb(N, 2) * 9 * 9;
    ans -= (9 - int(S[0] - '0')) * Comb(N - 1, 1) * 9;
    ans -= (9 - int(S[1] - '0'));
  } else {
    ans = Comb(N, 3) * 9 * 9 * 9;
    ans -= (9 - int(S[0] - '0')) * Comb(N - 1, 2) * 9 * 9;
    ans -= (9 - int(S[1] - '0')) * Comb(N - 2, 1) * 9;
    ans -= (9 - int(S[2] - '0'));
  }
  cout << ans << endl;
  return 0;
}
