#include <bits/stdc++.h>
using namespace std;
int a[105];
long long dp[105][5];
long long dfs(int pos, int state, bool lead, bool limit) {
  if (pos == -1)
    if (state == 0)
      return 1;
    else
      return 0;
  if (!limit && !lead && dp[pos][state] != -1) return dp[pos][state];
  int up = limit ? a[pos] : 9;
  long long ans = 0;
  for (int i = 0; i <= up; i++) {
    if (i)
      ans += dfs(pos - 1, state - 1, lead && i == 0, limit && i == a[pos]);
    else
      ans += dfs(pos - 1, state, lead && i == 0, limit && i == a[pos]);
  }
  if (!limit && !lead) dp[pos][state] = ans;
  return ans;
}
long long solve(string s, int k) {
  int pos = s.size();
  for (int i = 0; i < pos; i++) {
    a[i] = s[pos - i - 1] - '0';
  }
  return dfs(pos - 1, k, true, true);
}
int main() {
  string s;
  int k;
  cin >> s >> k;
  memset(dp, -1, sizeof(dp));
  cout << solve(s, k);
  return 0;
}
