#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int INF = 0x3f3f3f3f;
const double PI = 3.1415926535;
int main() {
  string n;
  int k;
  cin >> n;
  cin >> k;
  int len = n.size();
  if (k == 1) {
    long long ans = (len - 1) * 9;
    ans += n[0] - '0';
    cout << ans << endl;
  } else if (k == 2) {
    long long ans = (len - 1) * (len - 2) / 2 * 81;
    ans += (n[0] - '0' - 1) * 9 * (len - 1);
    int in = 1;
    while (n[in] == '0') in++;
    ans += n[in] - '0';
    ans += 9 * (len - in - 1);
    cout << ans << endl;
  } else if (k == 3) {
    long long ans = (len - 1) * (len - 2) * (len - 3) / 6 * 729;
    ans += (n[0] - '0' - 1) * 81 * (len - 1) * (len - 2) / 2;
    int in = 1;
    while (n[in] == '0') in++;
    int in2 = in + 1;
    while (n[in2] == '0') in2++;
    ans += (n[in2] - '0');
    ans += (9 * (len - in2 - 1));
    ans += (len - in - 1) * (len - in - 2) / 2 * 81;
    ans += (n[in] - '0' - 1) * 9 * (len - in - 1);
    cout << ans << endl;
  }
  return 0;
}
