#include <bits/stdc++.h>
using namespace std;
string n;
int k;
int digit[111];
long long dp[111][111];
long long dfs(int pos, int nonzero, bool limit) {
  if (pos == -1) {
    return nonzero == k;
  }
  if (!limit && dp[pos][nonzero] != -1) return dp[pos][nonzero];
  int up = limit ? digit[pos] : 9;
  long long ret = 0;
  for (int i = 0; i <= up; i++) {
    ret += dfs(pos - 1, nonzero + (i != 0), limit && i == digit[pos]);
  }
  if (!limit) dp[pos][nonzero] = ret;
  return ret;
}
int main() {
  memset(dp, -1L, sizeof dp);
  cin >> n >> k;
  for (int i = 0; i < n.size(); i++) digit[i] = n[i] - '0';
  cout << dfs(n.size() - 1, 0, true) << endl;
}
