#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int k;
  cin >> s >> k;
  long long n = s.size();
  if (k == 1) {
    n -= 1;
    cout << 9 * (n) + s[0] - '0';
  } else if (k == 2) {
    if (n == 1) {
      cout << "0";
      return 0;
    }
    n -= 2;
    if (s[0] == '1')
      cout << 9 * 9 * (n) * (n + 1) / 2;
    else
      cout << 9 * 9 * (n) * (n + 1) / 2 + (s[0] - '0' - 1) * 9 * (n + 1) +
                  n * 9 + s[1] - '0';
  } else {
    long long sum = 0;
    for (int i = 0; i < n - 3; i++) sum += (2 + i) * (2 + i - 1) / 2;
    if (s[0] == '1')
      cout << 9 * 9 * 9 * sum;
    else
      cout << 9 * 9 * 9 * sum +
                  (s[0] - '0' - 1) * 9 * 9 * (n - 2) * (n - 1) / 2 + s[2] -
                  '0' + 9 * 9 * (n - 2) * (n - 3) / 2;
  }
}
