#include <bits/stdc++.h>
using namespace std;
const int mods = 1e9 + 7;
const int maxn = 2e5 + 10;
const int N = 1e5 + 10;
const int E = 1e6 + 10;
string s;
long long n, k;
long long ans;
long long solve_1(long long del) {
  long long res = 0;
  res += (long long)(s[0 + del] - '0') + 9 * (n - 1 - del);
  return res;
}
long long solve_2(long long del) {
  long long res = 0;
  for (long long i = 0 + del; i < n; i++) {
    if (i == 0 + del) {
      res += solve_1(del + 1) +
             (long long)(s[0 + del] - '0' - 1) * 9 * (n - 1 - del);
    } else {
      res += 9 * 9 * (n - i - 1);
    }
  }
  return res;
}
long long solve_3(long long del) {
  long long res = 0;
  for (long long i = 0 + del; i < n; i++) {
    if (i == 0 + del) {
      res += solve_2(del + 1) +
             (long long)(s[0] - '0' - 1) * (((n - 1) * (n - 2)) / 2) * 81;
    } else {
      res += 9 * (((n - i - 1) * (n - i - 2)) / 2) * 81;
    }
  }
  return res;
}
int main() {
  cin >> s >> k;
  n = s.size();
  if (n < k) {
    printf("0\n");
    return 0;
  }
  if (k == 1) ans = solve_1(0);
  if (k == 2) ans = solve_2(0);
  if (k == 3) ans = solve_3(0);
  cout << ans << endl;
}
