#include <bits/stdc++.h>
using namespace std;
int main(void) {
  string s;
  cin >> s;
  int n = s.length();
  int a[101];
  int k;
  cin >> k;
  for (int i = 0; i < n; i++) {
    a[i] = s[i] - '0';
  }
  long long int ans = 0;
  if (k == 1) {
    ans = a[0] + (n - 1) * 9;
  } else if (k == 2) {
    if (n == 1) {
      ans = 0;
    } else if (n == 2) {
      ans = (a[0] - 1) * 9 + a[1];
    } else if (n > 3) {
      ans = ((a[0] - 1) * (n - 1) * 9) + (81 * (n - 1) * (n - 2) / 2) +
            ((n - 2) * 9 + a[1]);
    }
  } else if (k == 3) {
    if (n < 3) {
      ans = 0;
    } else if (n == 3) {
      ans = (a[0] - 1) * 81 + (a[1] - 1) * 9 + a[2];
    } else if (n > 3) {
      ans = ((a[0] - 1) * (n - 1) * (n - 2) * 81 / 2) +
            (729 * (n - 1) * (n - 2) * (n - 3) / 6) +
            (((a[1] - 1) * (n - 2) * 9) + (81 * (n - 2) * (n - 3) / 2) +
             ((n - 3) * 9 + a[2]));
    }
  }
  cout << ans;
  return 0;
}
