#include <bits/stdc++.h>
using namespace std;
int main() {
  string N;
  int K;
  cin >> N >> K;
  if (K == 1) {
    cout << ((char)N[0] - 48) + (N.length() - 1) * 9 << endl;
  } else if (K == 2) {
    if (N.length() == 1) {
      cout << 0 << endl;
    } else if (N.length() == 2) {
      int first = ((char)N[0] - 48);
      int second = ((char)N[1] - 48);
      cout << second + 9 * (first - 1) << endl;
    } else {
      int first = ((char)N[0] - 48);
      int second = ((char)N[1] - 48);
      int ketasuu = N.length();
      long total = second;
      if (second != 0) total += (ketasuu - 2) * 9;
      total += (first - 1) * (ketasuu - 1) * 9;
      int num_pair = (ketasuu - 1) * (ketasuu - 2) / 2;
      total += num_pair * 81;
      cout << total << endl;
    }
  } else {
    if (N.length() < 3) {
      cout << 0 << endl;
    } else if (N.length() == 3) {
      int first = ((char)N[0] - 48);
      int second = ((char)N[1] - 48);
      int third = ((char)N[2] - 48);
      cout << third + (second - 1) * 9 + (first - 1) * 91 << endl;
    } else {
      int first = ((char)N[0] - 48);
      int second = ((char)N[1] - 48);
      int third = ((char)N[2] - 48);
      int ketasuu = N.length();
      long long total = third;
      if (second != 0) total += (second - 1) * (ketasuu - 2) * 9;
      total += (first - 1) * (ketasuu - 1) * (ketasuu - 2) / 2 * 81;
      total += (ketasuu - 1) * (ketasuu - 2) * (ketasuu - 3) / 6 * (9 * 9 * 9);
      cout << total << endl;
    }
  }
  return 0;
}
