#include <bits/stdc++.h>
using namespace std;
int main() {
  int k, count = 2, e, f, ans = 0, l, m, n;
  string s;
  cin >> s >> k;
  char a, b = 'B', c = 'C';
  a = s.at(0);
  for (int i = 1; i < s.size(); i++) {
    if (s.at(i) != '0' && b == 'B') {
      b = s.at(i);
      e = s.size() - count + 1;
    } else if (s.at(i) != '0' && b != 'B' && c == 'C') {
      c = s.at(i);
      f = s.size() - count + 1;
    }
    count++;
  }
  a = a - '0';
  m = b - '0';
  n = c - '0';
  l = s.size() - 1;
  if (k == 1) {
    ans += 9 * l + a;
  } else if (k == 2 && b != 'B') {
    ans += l * (l - 1) / 2 * 81;
    ans += 9 * l * (a - 1);
    if (b != 'B') {
      ans += 9 * (e - 1) + m;
    }
  } else if (k == 3) {
    ans += l * (l - 1) * (l - 2) / 2 * 243;
    ans += l * (l - 1) / 2 * 81 * (a - 1);
    if (b != 'B') {
      ans += (e - 1) * (e - 2) / 2 * 81;
      ans += (m - 1) * (e - 1) * 9;
    }
    if (b != 'B' && c != 'C') {
      ans += 9 * (f - 1) + n;
    }
  }
  cout << ans << endl;
}
