#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
int GetDigit(long long num) {
  if (num == 0) return 1;
  int digit = 0;
  while (num != 0) {
    num /= 10;
    digit++;
  }
  return digit;
}
int TopDigit(long long num) {
  if (num == 0) return 0;
  int top = 0;
  while (num != 0) {
    top = num % 10;
    num /= 10;
  }
  return top;
}
int main(void) {
  string n;
  cin >> n;
  int k;
  cin >> k;
  int d = n.length();
  int T1 = n[0] - '0';
  int T2 = n[1] - '0';
  int T3 = n[2] - '0';
  long long ans = 0;
  for (int i = 1; i < d; i++) {
    if (k == 1 && k <= i) {
      ans += 9;
    } else if (k == 2 && k <= i) {
      ans += 9 * (i - 1) * 9;
    } else if (k == 3 && k <= i) {
      ans += 9 * (((i - 1) * (i - 2)) / 2) * 9 * 9;
    }
  }
  if (k == 1) {
    ans += T1;
  } else if (k == 2 && d >= 2) {
    ans += (T1 - 1) * (d - 1) * 9;
    ans += T2 + (d - 2) * 9;
  } else if (k == 3 && d >= 3) {
    ans += (T1 - 1) * (((d - 1) * (d - 2)) / 2) * 9 * 9;
    ans += (T3 + 9 * (d - 3));
    ans += (T2 - 1) * 9 * (d - 2);
    ans += 9 * 9 * (((d - 2) * (d - 3)) / 2);
  }
  cout << ans << endl;
  return 0;
}
