#include <bits/stdc++.h>
using namespace std;
long long comb(long long n, int r) {
  long long ret;
  switch (r) {
    case 1:
      ret = n;
      break;
    case 2:
      ret = (n * (n - 1)) / 2;
      break;
    case 3:
      ret = (n * (n - 1) * (n - 2)) / 6;
      break;
  }
  return ret;
}
long long dp[101][4];
int main() {
  string N;
  int K, len;
  cin >> N >> K;
  len = N.length();
  for (int i = (1); i <= (len); i++) {
    if (i == 1) {
      dp[i][1] = ((long long)(N[len - i] - '0'));
    } else if (i == 2) {
      dp[i][1] = (i - 1) * 9 + ((long long)(N[len - i] - '0'));
      if (((long long)(N[len - i] - '0')) == 0) {
        dp[i][2] = dp[i - 1][2];
      } else {
        dp[i][2] += dp[i - 1][2];
        dp[i][2] += (((long long)(N[len - i] - '0')) - 1) * 9;
        dp[i][2] += dp[i - 1][1];
      }
    } else {
      dp[i][1] = (i - 1) * 9 + ((long long)(N[len - i] - '0'));
      if (((long long)(N[len - i] - '0')) == 0) {
        dp[i][2] = dp[i - 1][2];
      } else {
        if (i > 2) dp[i][2] += comb(i - 1, 2) * 9 * 9;
        dp[i][2] += (((long long)(N[len - i] - '0')) - 1) * comb(i - 1, 1) * 9;
        dp[i][2] += dp[i - 1][1];
      }
      if (((long long)(N[len - i] - '0')) == 0) {
        dp[i][3] = dp[i - 1][3];
      } else {
        if (i > 3) dp[i][3] += comb(i - 1, 3) * 9 * 9 * 9;
        dp[i][3] +=
            (((long long)(N[len - i] - '0')) - 1) * comb(i - 1, 2) * 9 * 9;
        dp[i][3] += dp[i - 1][2];
      }
    }
  }
  cout << dp[len][K] << endl;
  return 0;
}
