#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  string s;
  int k;
  cin >> s >> k;
  int n = s.size();
  if (k > n) {
    cout << 0;
    return 0;
  }
  if (k == 1) {
    cout << 9 * (n - 1) + (s[0] - '0');
  } else if (k == 2) {
    cout << 81 * (n - 2) * (n - 1) / 2 + (s[0] - '1') * 9 * (n - 1) +
                (s[1] - '0') + 9 * (n - 2);
  } else {
    int ans = 729 * (n - 1) * (n - 2) * (n - 3) / 6 +
              (s[0] - '1') * 81 * (n - 1) * (n - 2) / 2 +
              81 * (n - 2) * (n - 3) / 2 + (s[2] - '0') + 9 * (n - 3);
    if (s[1] != '0') {
      cout << ans + (s[1] - '1') * 9 * (n - 2);
    } else {
      cout << ans;
    }
  }
  return 0;
}
