#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;
  cin >> n;
  int k;
  long long c = 0;
  cin >> k;
  long long ans = 0;
  long long t;
  t = n.size();
  if (k == 1) {
    cout << (t - 1) * 9 + n[0] - '0' << endl;
  } else if (k == 2) {
    if (t < 2) {
      cout << 0 << endl;
      return 0;
    }
    ans += (t - 1) * (t - 2) / 2 * (long long)(9 * 9);
    ans += max((long long)0, (long long)(n[0] - '0' - 1)) * (t - 1) * 9;
    cout << ans << endl;
    long long c = 0;
    c++;
    t--;
    while (n[c] == '0' && c < n.size()) {
      c++;
      t--;
    }
    if (c == n.size()) {
      cout << ans << endl;
      return 0;
    }
    ans += (t - 1) * 9 + n[c] - '0';
    cout << ans << endl;
  } else if (k == 3) {
    if (t < 3) {
      cout << 0 << endl;
      return 0;
    }
    ans += (t - 1) * (t - 2) * (t - 3) / (long long)6 * (long long)(9 * 9 * 9);
    ans += max((long long)0, (long long)(n[0] - '0' - 1)) * (t - 1) * (t - 2) /
           2 * (long long)(9 * 9);
    long long c = 0;
    c++;
    t--;
    while (n[c] == '0' && c < n.size()) {
      c++;
      t--;
    }
    if (c == n.size()) {
      cout << ans << endl;
      return 0;
    }
    ans += (t - 1) * (t - 2) / 2 * (long long)(9 * 9);
    ans += max((long long)0, (long long)(n[c] - '0' - 1)) * (t - 1) * 9;
    cout << ans << endl;
    c++;
    t--;
    while (n[c] == '0' && c < n.size()) {
      c++;
      t--;
    }
    if (c == n.size()) {
      cout << ans << endl;
      return 0;
    }
    ans += (t - 1) * 9 + n[c] - '0';
    cout << ans << endl;
  }
  return 0;
}
