#include <bits/stdc++.h>
using namespace std;
using ll = long long;
string N;
int n;
int dfs(int keta, int rest, bool lower) {
  if (rest < 0) return 0;
  if (keta == n) return rest > 0 ? 0 : 1;
  if (lower) {
    return 9 * dfs(keta + 1, rest - 1, lower) + dfs(keta + 1, rest, lower);
  }
  int D = N[keta] - '0';
  int ans = dfs(keta + 1, rest, (D > 0));
  ans += (D - 1) * dfs(keta + 1, rest - 1, true);
  ans += dfs(keta + 1, rest - 1, false);
  return ans;
}
int main() {
  int K;
  cin >> N >> K;
  n = N.size();
  ll ans = 0;
  ans += dfs(1, K, true);
  ans += ((N[0] - '0') - 1) * dfs(1, K - 1, true);
  ans += dfs(1, K - 1, false);
  cout << ans << endl;
  return 0;
}
