#include <bits/stdc++.h>
using namespace std;
string s;
int k, m = 0, t, u, v, w;
int main() {
  cin >> s >> k;
  t = s.size();
  u = s[0] - '0';
  if (s.size() > 1) v = s[1] - '0';
  if (s.size() > 2) w = s[2] - '0';
  if (t > k) {
    if (k == 1)
      m = 9 * (t - 1);
    else if (k == 2)
      m = 81 * ((t - 1) * (t - 2)) / 2;
    else
      m = 243 * ((t - 1) * (t - 2) * (t - 3)) / 2;
  }
  if (t >= k) {
    if (k == 1)
      m += u;
    else if (k == 2)
      m += (u - 1) * 9 * (t - 1) + 9 * (t - 2) + v;
    else {
      m += (u - 1) * 81 * ((t - 1) * (t - 2)) / 2 +
           81 * ((t - 2) * (t - 3)) / 2 + (v - 1) * 9 * (t - 2) + 9 * (t - 3) +
           w;
    }
  }
  cout << m << endl;
  return 0;
}
