#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  short negative = 1;
  x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') negative = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  x *= negative;
}
int main() {
  string n;
  int k;
  cin >> n >> k;
  if (k == 1) {
    long long ans = 0;
    ans += n[0] - '0';
    ans += (n.size() - 1) * 9;
    cout << ans << endl;
    return 0;
  } else if (k == 2) {
    long long ans = 0;
    ans += (n.size() - 1) * (n.size() - 2) / 2 * (long long)9 * 9;
    long long ans1 = ans;
    ans += max((long long)0, (long long)((n[0] - '1') * (n.size() - 1) * 9));
    ans = max(ans1, ans);
    int now = 1;
    for (; now < n.size(); now++) {
      if (n[now] != 0) break;
    }
    if (now != n.size()) ans += (n.size() - now - 1) * 9 + (n[now] - '0');
    cout << ans << endl;
  } else if (k == 3) {
    long long ans = 0;
    ans += (n.size() - 1) * (n.size() - 2) * (n.size() - 3) / (long long)6 *
           (long long)9 * 9 * 9;
    long long ans1 = ans;
    ans += (long long)(n[0] - '1') * (n.size() - 1) * (n.size() - 2) / 2 *
           (long long)9 * 9;
    ans = max(ans1, ans);
    long long now = 1;
    for (; now < n.size(); now++) {
      if (n[now] != 0) break;
    }
    if (now != n.size()) {
      ans += (n.size() - now - 1) * (n.size() - now - 2) / 2 * (long long)9 * 9;
      ans += (long long)(n[now] - '1') * (n.size() - now - 1) * 9;
      now++;
      for (; now < n.size(); now++)
        if (n[now] != 0) break;
      if (now != n.size()) {
        ans += (n.size() - now - 1) * 9 + (n[now] - '0');
      }
    }
    cout << ans << endl;
  }
  return 0;
}
