#include <bits/stdc++.h>
using namespace std;
long long div_floor(long long a, long long b) {
  return a / b - (((a ^ b) < 0) and a % b);
}
long long div_ceil(long long a, long long b) {
  return a / b + (((a ^ b) >= 0) and a % b);
}
const int sz = 1e3 + 9;
long long dp[sz][4][3];
string second;
int k;
long long solve(int idx, int rem, int can) {
  long long &ret = dp[idx][rem][can];
  if (!idx) return ret = !rem;
  if (~ret) return ret;
  int val = second[idx] - '0';
  if (!rem) return ret = solve(idx - 1, rem, can);
  ret = 0;
  if (can)
    ret = 9 * solve(idx - 1, rem - 1, 1) + solve(idx - 1, rem, 1);
  else {
    if (val) ret = solve(idx - 1, rem - 1, can);
    for (int i = 0; i < val; i++) ret += solve(idx - 1, rem - (i > 0), can | 1);
  }
  return ret;
}
int main() {
  cin >> second >> k;
  reverse(second.begin(), second.end());
  second = "0" + second;
  memset(dp, -1, sizeof(dp));
  cout << solve(second.size() - 1, k, 0);
  return 0;
}
