#include <bits/stdc++.h>
using namespace std;
int binomialCoeff(int n, int k) {
  if (k > n) return 0;
  if (k == 0 || k == n) return 1;
  return binomialCoeff(n - 1, k - 1) + binomialCoeff(n - 1, k);
}
int main() {
  string n;
  cin >> n;
  int k;
  cin >> k;
  int len = n.length();
  reverse(n.begin(), n.end());
  long long int arr[len + 1][k + 1];
  memset(arr, 0, sizeof(arr));
  for (int i = 0; i < len + 1; i++) {
    for (int j = 0; j <= k; j++) {
      if (j > i) {
        arr[i][j] = 0;
        continue;
      }
      if (j == 0 || i == 0)
        arr[i][j] = 0;
      else {
        arr[i][j] =
            (n[i - 1] - '0' - 1) * pow(9, j - 1) * binomialCoeff(i - 1, j - 1) +
            arr[i - 1][j - 1] + binomialCoeff(i - 1, j) * pow(9, j);
      }
    }
  }
  cout << arr[len][k] + 1;
}
