#include <bits/stdc++.h>
using namespace std;
long long ans1(string n) {
  int cnt = n.size();
  long long ans = 0;
  ans += (cnt - 1) * 9 + n.at(0) - '0';
  return ans;
}
long long ans2(string n) {
  int cnt = n.size();
  long long sub = 0;
  for (int i = 2; i <= cnt - 1; i++) {
    sub += 81 * (i - 1);
  }
  long long ans = sub;
  string t;
  for (int i = 0; i < cnt - 1; i++) t += n.at(i + 1);
  string u;
  for (int i = 0; i < cnt - 1; i++) u += "9";
  sub = (n.at(0) - 1 - '0') * ans1(u);
  ans += sub;
  ans += ans1(t);
  return ans;
}
int main() {
  using ll = long long;
  string n;
  cin >> n;
  int k;
  cin >> k;
  if (k == 1) {
    ll ans = ans1(n);
    cout << ans << endl;
  } else if (k == 2) {
    int cnt = n.size();
    if (cnt == 1)
      cout << 0 << endl;
    else {
      ll ans = ans2(n);
      cout << ans << endl;
    }
  } else {
    int cnt = n.size();
    if (cnt <= 2)
      cout << 0 << endl;
    else {
      ll sub = 0;
      for (int i = 3; i <= cnt - 1; i++) {
        sub += 729 * (i - 1) * (i - 2) / 2;
      }
      ll ans = sub;
      string u;
      for (int i = 0; i < cnt - 1; i++) u += "9";
      ans += (n.at(0) - 1 - '0') * ans2(u);
      string t;
      for (int i = 0; i < cnt - 1; i++) t += n.at(i + 1);
      ans += ans2(t);
      cout << ans << endl;
    }
  }
}
