#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
int main() {
  string S;
  cin >> S;
  ll K;
  cin >> K;
  ll N = ((ll)(S).size());
  ll dp[N + 1][2][N + 1];
  for (ll(i) = (0), (i_len) = (N + 1); (i) < (i_len); ++(i)) {
    for (ll(smaller) = (0), (i_len) = (2); (smaller) < (i_len); ++(smaller)) {
      for (ll(k) = (0), (i_len) = (N + 1); (k) < (i_len); ++(k)) {
        dp[i][smaller][k] = 0;
      }
    }
  }
  dp[0][0][0] = 1;
  for (ll(i) = (0), (i_len) = (N); (i) < (i_len); ++(i)) {
    for (ll(smaller) = (0), (i_len) = (2); (smaller) < (i_len); ++(smaller)) {
      for (ll(k) = (0), (i_len) = (N); (k) < (i_len); ++(k)) {
        for (ll(n) = (0), (i_len) = (smaller ? 10 : (S[i] - '0') + 1);
             (n) < (i_len); ++(n)) {
          dp[i + 1][smaller || n < (S[i] - '0')][k + (n > 0)] +=
              dp[i][smaller][k];
        }
      }
    }
  }
  cout << (dp[N][0][K] + dp[N][1][K]) << endl;
  return 0;
}
