#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string N;
  long long K;
  cin >> N >> K;
  long long len = N.size();
  vector<vector<long long>> t_dp(len, vector<long long>(5, 0));
  vector<vector<long long>> dp(len, vector<long long>(5, 0));
  for (long long i = 0; i <= 4; ++i) {
    t_dp[0][i] = 0;
    dp[0][i] = 0;
  }
  t_dp[0][1] = 1;
  dp[0][1] = N[0] - '0' - 1;
  dp[0][0] = 1;
  for (long long i = 1; i < len; ++i) {
    long long c = N[i] - '0';
    if (c == 0) {
      t_dp[i][0] = t_dp[i - 1][0];
      t_dp[i][1] = t_dp[i - 1][1];
      t_dp[i][2] = t_dp[i - 1][2];
      t_dp[i][3] = t_dp[i - 1][3];
      t_dp[i][4] = t_dp[i - 1][4];
    } else {
      t_dp[i][0] = 0;
      t_dp[i][1] = t_dp[i - 1][0];
      t_dp[i][2] = t_dp[i - 1][1];
      t_dp[i][3] = t_dp[i - 1][2];
      t_dp[i][4] = t_dp[i - 1][3] + t_dp[i - 1][4];
    }
    dp[i][0] = dp[i - 1][0];
    dp[i][1] = dp[i - 1][1] + dp[i - 1][0] * 9 + t_dp[i - 1][0] * (N[i] - 1);
    dp[i][2] = dp[i - 1][2] + dp[i - 1][1] * 9 + t_dp[i - 1][1] * (N[i] - 1);
    dp[i][3] = dp[i - 1][3] + dp[i - 1][2] * 9 + t_dp[i - 1][2] * (N[i] - 1);
    dp[i][4] = dp[i - 1][4] + dp[i - 1][3] * 9 + t_dp[i - 1][3] * (N[i] - 1);
  }
  long long ans = dp[len - 1][K] + t_dp[len - 1][K];
  cout << ans << endl;
}
