#include <bits/stdc++.h>
using namespace std;
int main() {
  string N;
  int K;
  cin >> N >> K;
  int len = (int)(N.length());
  int digit[len];
  for (int i = 0; i < len; i++) {
    digit[len - 1 - i] = (int)(N[i]) - 48;
  }
  if (K == 1) {
    cout << (9 * (len - 1) + digit[len - 1]);
    return 0;
  } else if (K == 2) {
    long long sum = 0;
    for (int j = 2; j <= len - 1; j++) {
      sum += (9 * (j - 1));
    }
    for (int j = 1; j <= digit[len - 1] - 1; j++) {
      sum += (9 * (len - 1));
    }
    for (int j = 0; j <= len - 2; j++) {
      sum += digit[j];
    }
    cout << sum;
    return 0;
  } else {
    long long sum = 0;
    if (len <= 2) {
      cout << 0;
      return 0;
    }
    for (int j = 3; j <= len - 1; j++) {
      sum += (9 * 9 * 9 * (((j - 1) * (j - 2)) / 2));
    }
    for (int j = 1; j <= digit[len - 1] - 1; j++) {
      sum += (9 * 9 * (((len - 1) * (len - 2)) / 2));
    }
    for (int j = 1; j <= len - 2; j++) {
      for (int k = 0; k < j; k++) {
        sum += (digit[j] * digit[k]);
      }
    }
    cout << sum;
    return 0;
  }
  return 0;
}
