#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int, int>;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e9;
const ll LINF = (ll)1e18;
const int INTMAX = 2147483647;
template <class t, class u>
void chmax(t& a, u b) {
  if (a < b) a = b;
}
template <class t, class u>
void chmin(t& a, u b) {
  if (b < a) a = b;
}
int main() {
  string s;
  cin >> s;
  int n = s.size();
  int K;
  cin >> K;
  vector<vector<vl>> dp(n + 10, vector<vl>(2, vl(K + 1, 0)));
  dp[0][0][0] = 1;
  for (int i = 0; i < n; ++i) {
    int D = s[i] - '0';
    for (int j = 0; j < 2; ++j) {
      for (int k = 0; k <= K; ++k) {
        for (int d = 0; d <= (j ? 9 : D); ++d) {
          if (d == 0) {
            dp[i + 1][j || (d < D)][k] += dp[i][j][k];
          } else
            dp[i + 1][j || (d < D)][k + 1] += dp[i][j][k];
        }
      }
    }
  }
  cout << dp[n][0][K] + dp[n][1][K] << endl;
}
