#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
int dx4[4] = {1, 0, -1, 0}, dy4[4] = {0, 1, 0, -1};
int main() {
  ll zero = 0;
  string n;
  ll k;
  cin >> n >> k;
  ll s = n.size();
  ll nn[3];
  for (int i = 0; i < 3; i++) {
    if (i < s) {
      nn[i] = n[i] - '0';
    }
  }
  ll ans = 0;
  if (k == 1) {
    ans = nn[0] + 9 * (s - 1);
  } else if (k == 2) {
    if (s >= 2) {
      ans += nn[1];
      ans += (nn[0] - 1) * 9;
    }
    if (s >= 3) {
      ans += nn[0] * 9 * (s - 2);
      ans += 9LL * 9 * (s - 1) * (s - 2) / 2;
    }
  } else {
    ll test = 1 / zero;
    if (s >= 3) {
      ans += nn[2];
      ans += 9 * (s - 3);
      ans += max(0LL, nn[1] - 1) * 9;
      ans += max(0LL, nn[1] - 1) * 9 * (s - 3);
      ans += 9LL * 9 * (s - 2) * (s - 3) / 2;
      ans += max(0LL, nn[0] - 1) * 9 * 9 * (s - 1) * (s - 2) / 2;
    }
    if (s >= 4) {
      ans += 9LL * 9 * 9 * (s - 1) * (s - 2) * (s - 3) / 6;
    }
  }
  cout << ans << endl;
  return 0;
}
