#include <bits/stdc++.h>
using namespace std;
long long dp[105][4] = {0};
int main() {
  int k;
  string s;
  cin >> s >> k;
  int n = s.size();
  long long ans = 0;
  dp[0][1] = 0;
  dp[0][2] = 0;
  dp[0][3] = 0;
  for (int i = 1; i <= n; i++) dp[i][1] = 9 * i;
  for (int j = 2; j <= 3; j++) {
    for (int i = 1; i <= n; i++) {
      for (int kk = 1; kk < i; kk++) dp[i][j] += 9 * dp[kk][j - 1];
    }
  }
  if (n < k) {
    cout << "0\n";
    return 0;
  }
  if (k == 1) {
    cout << dp[n - 1][1] + (s[0] - '0');
    return 0;
  }
  if (k == 2) {
    cout << dp[n - 1][2] + (s[0] - '0' - 1) * dp[n - 1][1] + dp[n - 2][1] +
                (s[1] - '0');
  }
  if (k == 3) {
    cout << dp[n - 1][3] + (s[0] - '0' - 1) * dp[n - 1][2] + dp[n - 2][2] +
                (s[1] - '0' - 1) * dp[n - 2][1] + dp[n - 3][1] + (s[2] - '0');
  }
}
