#include <bits/stdc++.h>
using namespace std;
long long k, s, u, n, v;
string t;
int gth(long long x) {
  long long w = 1;
  for (int i = 1; i <= x; i++) {
    w = w * i;
  }
  return w;
}
int main() {
  cin >> t >> k;
  if (k == 1) {
    s = (t.size() - 1) * 9;
    u = t[0];
    s = s + u - 48;
  } else if (k == 2) {
    if (n < 11) {
      cout << 0;
      return 0;
    }
    u = t.size() - 1;
    s = ((u * (u - 1)) / 2) * 81;
    u = t[0];
    u = u - 48;
    s = s + (u - 1) * (t.size() - 1) * 9;
    s = s + (t.size() - 2) * 9;
    u = t[1];
    u = u - 48;
    s = s + u;
  } else {
    if (n < 111) {
      cout << 0;
      return 0;
    }
    u = t.size() - 1;
    s = ((u * (u - 1) * (u - 2)) / 6) * 729;
    u = t[0];
    u = u - 48;
    v = t.size() - 1;
    s = s + (u - 1) * ((v * (v - 1)) / 2) * 81;
    s = s + (((v - 1) * (v - 2)) / 2) * 81;
    u = t[1];
    u = u - 48;
    s = s + (u - 1) * (t.size() - 2) * 9;
    s = s + (t.size() - 3) * 9;
    u = t[2];
    u = u - 48;
    s = s + u;
  }
  cout << s;
}
