#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string n;
  long long k;
  cin >> n >> k;
  long long sz = n.size();
  if (k == 1) {
    long long ans = n[0] - '0';
    for (long long i = 1; i < sz; i++) {
      ans += 9;
    }
    cout << ans;
    return 0;
  } else if (k == 2) {
    if (sz < 2) {
      cout << 0;
      return 0;
    }
    long long ans = 0;
    vector<vector<long long> > dp(sz, vector<long long>(2, 0));
    dp[1][0] = 1;
    dp[1][1] = n[1] - '0';
    for (long long i = 2; i < sz; i++) {
      dp[i][0] = dp[i - 1][0];
      dp[i][1] = dp[i - 1][0] * (n[i] - '0') + dp[i - 1][1];
    }
    ans += (n[1] - '0') + (sz - 2) * 9;
    dp.assign(sz, vector<long long>(3, 0));
    dp[0][0] = 1;
    dp[0][1] = n[0] - 1 - '0';
    for (long long i = 1; i < sz; i++) {
      dp[i][0] = dp[i - 1][0];
      dp[i][1] = dp[i - 1][1] + dp[i - 1][0] * 9;
      dp[i][2] = dp[i - 1][2] + dp[i - 1][1] * 9;
    }
    ans += 1ULL * dp[sz - 1][2];
    cout << ans;
    return 0;
  } else if (k == 3) {
    if (sz < 3) {
      cout << 0;
      return 0;
    }
    cout << 1 + (sz - 3) * 9ULL + max(n[2] - '0' - 1, 0) * 1ULL +
                1ULL * ((sz - 2) * (sz - 3) / 2) * 81 +
                1ULL * max(n[1] - '0' - 1, 0) * (sz - 2) * 9 +
                1ULL * ((sz - 1) * (sz - 2) * (sz - 3) / 6) * 9 * 9 * 9 +
                1ULL * max(n[0] - '0' - 1, 0) * ((sz - 1) * (sz - 2) / 2) * 81;
  }
}
