#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
int main() {
  string S;
  cin >> S;
  ll K;
  cin >> K;
  ll digit = S.size();
  vector<vector<vector<ll> > > dp(digit,
                                  vector<vector<ll> >(2, vector<ll>(K + 1, 0)));
  for (int i = 0; i < digit; i++) {
    int x = S[i] - '0';
    if (i == 0) {
      dp[0][0][0] = 1;
      dp[0][0][1] = x - 1;
      dp[0][1][0] = 0;
      dp[0][1][1] = 1;
    } else {
      for (int k = 0; k <= K; k++) {
        if (x == 0) {
          if (k == 0) {
            dp[i][0][0] = dp[i - 1][0][0];
            dp[i][1][0] = 0;
          } else {
            dp[i][0][k] =
                dp[i - 1][0][k] + dp[i - 1][0][k - 1] * 9 + dp[i - 1][1][k - 1];
            dp[i][1][k] = dp[i - 1][1][k];
          }
        } else {
          if (k == 0) {
            dp[i][0][0] = dp[i - 1][0][0] + dp[i - 1][1][0];
            dp[i][1][0] = dp[i - 1][1][0];
          } else {
            dp[i][0][k] = dp[i - 1][0][k] + dp[i - 1][0][k - 1] * 9 +
                          dp[i - 1][1][k] + dp[i - 1][1][k - 1] * (x - 1);
            dp[i][1][k] = dp[i - 1][1][k - 1];
          }
        }
      }
    }
  }
  cout << dp[digit - 1][0][K] + dp[digit - 1][1][K] << endl;
  return 0;
}
