#include <bits/stdc++.h>
using namespace std;
long long p[200000];
long long p_sums[200000];
long long combin(int n, int m) {
  long long numerator = 1;
  for (int i = 0; i < m; i++) {
    numerator *= (n - i);
  }
  long long denominator = 1;
  for (int i = 0; i < m; i++) {
    denominator *= (i + 1);
  }
  return numerator / denominator;
}
long long power(int n, int m) {
  long long ans = 1;
  for (int i = 0; i < m; i++) {
    ans *= (long long)n;
  }
  return ans;
}
int main(void) {
  string S;
  int K;
  cin >> S;
  cin >> K;
  int N = S.size();
  long long ans = 0;
  for (int i = K; i <= N - 1; i++) {
    ans += power(9, K) * combin(i - 1, K - 1);
  }
  ans += (long long)(S[0] - '1') * power(9, K - 1) * combin(N - 1, K - 1);
  if (K == 1) {
    ans++;
  } else if (K == 2) {
    if (N >= 2) {
      ans += (long long)(S[1] - '0');
      ans += (N - 2) * (long long)9;
    }
  } else {
    if (N >= 3) {
      ans += power(9, K - 1) * combin(N - 2, K - 1);
      if (S[1] > '1') {
        ans += (long long)(S[1] - '1') * (N - 2) * (long long)9;
      }
      ans += (long long)(S[2] - '0') + (N - 3) * (long long)9;
    }
  }
  cout << ans << endl;
  return 0;
}
