#include <bits/stdc++.h>
using namespace std;
int compare(string s, string t) {
  if (s.size() > t.size()) {
    return 1;
  } else if (s.size() < t.size()) {
    return 0;
  }
  for (int i = 0; i < s.size(); i++) {
    if (s[i] - '0' > t[i] - '0') {
      return 1;
      break;
    } else if (s[i] - '0' < t[i] - '0') {
      return 0;
      break;
    }
  }
  return 1;
}
int main() {
  string n;
  long long k;
  cin >> n >> k;
  if (n.size() == 1) {
    cout << n << endl;
  } else {
    map<string, long long> data;
    queue<string> qe;
    for (int i = 1; i < 10; i++) {
      string h = to_string(i);
      data[h] = 1;
      qe.push(h);
    }
    long long count = 0;
    while (1) {
      string res = qe.front();
      string v = res;
      qe.pop();
      if (data[res] < k) {
        string s = res;
        res = s + '0';
        qe.push(res);
        data[res] = data[s];
        for (int i = 1; i < 10; i++) {
          char j = i + '0';
          res = s + j;
          data[res] = data[s] + 1;
          qe.push(res);
        }
      } else {
        string s = res;
        res = s + '0';
        qe.push(res);
        data[res] = data[s];
      }
      if (compare(n, v) == 0) {
        break;
      }
      if (data[v] == k) {
        if (compare(n, v) == 1) {
          count += 1;
        }
      }
    }
    cout << count << endl;
  }
}
