#include <bits/stdc++.h>
using namespace std;
long long t;
string s;
long long one(long long a, long long b) {
  long long c, d, e, f, i, j;
  a = a * 9;
  a += b;
  return a;
}
long long two(long long a, long long k) {
  long long b, c, d, e, f = 0, g, i, j;
  e = s.size();
  for (i = k; i < e; i++) {
    b = s[i] - '0';
    if (b != 0) break;
  }
  f += one(e - i - 1, b);
  if (i == e) f = 0;
  d = a - 1;
  d = d * (d - 1);
  d /= 2;
  f += (d * 81);
  a--;
  c = s[0] - '0';
  c--;
  f += (c * 9 * a);
  return f;
}
vector<long long> v;
int main() {
  long long a, b, c, d, e, f, g, i, j;
  cin >> s >> a;
  f = 0;
  b = s.size();
  if (b < a)
    cout << '0' << endl;
  else if (a == 1) {
    b--;
    f = s[0] - '0';
    cout << one(b, f) << endl;
  } else if (a == 2) {
    cout << two(b, 1) << endl;
  } else {
    f = 0;
    for (i = 1; i < b; i++) {
      d = s[i] - '0';
      if (d != 0) break;
    }
    if (i != b) {
      f += two(b - i, i + 1);
    }
    c = s[0] - '0';
    c--;
    for (i = 0; i < b - 2; i++) {
      for (j = i + 1; j < b - 1; j++) {
        for (long long k = j + 1; k < b; k++) {
          if (k != b - 1)
            f += 729;
          else
            f += (81 * c);
        }
      }
    }
    cout << f << endl;
  }
  return 0;
}
