#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAX = 510000;
const ll MOD = 1e18 + 7;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  int k;
  cin >> s >> k;
  if (k == 1) {
    int x = s.at(0) - 48;
    cout << (s.size() - 1) * 9 + x << '\n';
  }
  COMinit();
  if (k == 2) {
    if (s.size() < 2) {
      cout << 0 << '\n';
      return 0;
    }
    int x = s.at(0) - 48, y = s.at(1) - 48;
    ll ans = (s.size() - 1) * (s.size() - 2) / 2 * 81;
    ans += (s.size() - 2) * x * 9;
    ans += (x - 1) * 9 + y;
    cout << ans << '\n';
  }
  if (k == 3) {
    if (s.size() < 3) {
      cout << 0 << '\n';
      return 0;
    }
    int x = s.at(0) - 48, y = s.at(1) - 48, z = s.at(2) - 48;
    ll ans = (s.size() - 1) * (s.size() - 2) * (s.size() - 3) / 6 * 729;
    ans += x * (s.size() - 2) * (s.size() - 3) / 2 * 81;
    ans += ((x - 1) * 9 + y) * (s.size() - 3) * 9;
    if (y != 0)
      ans += (x - 1) * 81 + (y - 1) * 9 + z;
    else
      ans += (x - 1) * 81;
    cout << ans << '\n';
  }
}
