#include <bits/stdc++.h>
using namespace std;
int k2(string n, int n_size, int left) {
  int ans;
  if (n_size == 1) {
    ans = 0;
  } else if (n_size == 2) {
    ans = 9 * (left - 1) + stoi(n.substr(1, 1));
  } else {
    ans = 0;
    for (int i = 2; i <= n_size - 1; i++) {
      ans += (i - 1) * 9 * 9;
    }
    ans += (n_size - 1) * 9 * (left - 1);
    ans += stoi(n.substr(1, 1));
    bool flag = false;
    if (stoi(n.substr(1, 1)) != 0) {
      flag = true;
    }
    for (int i = 2; i <= n_size - 1; i++) {
      if (flag == true) {
        ans += 9;
      } else {
        ans += stoi(n.substr(i, 1));
      }
      if (stoi(n.substr(i, 1)) != 0) {
        flag = true;
      }
    }
  }
  return ans;
}
int main() {
  string n;
  int k;
  cin >> n >> k;
  int n_size = n.size();
  int left = stoi(n.substr(0, 1));
  int ans;
  if (k == 1) {
    if (n_size == 1) {
      ans = left;
    } else {
      ans = 9 * (n_size - 1) + left;
    }
  }
  if (k == 2) {
    ans = k2(n, n_size, left);
  }
  if (k == 3) {
    if (n_size == 1 || n_size == 2) {
      ans = 0;
    } else if (n_size == 3) {
      int left1 = stoi(n.substr(1, 1));
      ans = 81 * (left - 1) + 9 * (left1 - 1) + stoi(n.substr(2, 1));
    } else {
      ans = 0;
      for (int i = 3; i <= n_size - 1; i++) {
        ans += i * (i - 1) / 2 * 9 * 9 * 9;
      }
      ans += (n_size - 1) * (n_size - 1) / 2 * 9 * 9 * (left - 1);
      ans += k2(n.substr(1, n_size - 1), n_size - 1, stoi(n.substr(1, 1)));
    }
  }
  cout << ans << endl;
}
