#include <bits/stdc++.h>
using namespace std;
int main() {
  string N;
  int K;
  cin >> N >> K;
  int n = N.size();
  int a = (int)(N.at(0) - '0'), b = (int)(N.at(min(1, n - 1)) - '0'),
      c = (int)(N.at(min(2, n - 2)) - '0');
  long long ans = 0;
  if (K == 1) {
    ans += a + 9 * (n - 1);
  } else if (K == 2) {
    ans += (a - 1) * (n - 1) * 9 + b + max(0, n - 2) * 9 +
           max(0, n - 2) * (n - 1) * 81 / 2;
  } else {
    ans += (a - 1) * (n - 1) * max(0, n - 2) / 2 * 81 +
           (b - 1) * max(0, n - 2) * 9 + c + max(0, n - 3) * 9 +
           max(0, n - 2) * max(0, n - 3) / 2 * 81 +
           max(0, n - 2) * max(n - 3, 0) * (n - 1) * 9 * 9 * 9 / 6;
  }
  cout << ans << endl;
}
