#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll ans = 0;
int main() {
  string S;
  cin >> S;
  int N = ((int)(S).size());
  int K;
  cin >> K;
  vector<vector<vector<ll>>> dp(N + 1,
                                vector<vector<ll>>(2, vector<ll>(K + 1, 0)));
  dp[0][0][0] = 1;
  for (int i = 0; i < (N); i++) {
    for (int smaller = 0; smaller < (2); smaller++) {
      for (int k = 0; k < (K + 1); k++) {
        for (int x = 0; x <= (smaller ? 9 : (int)(S[i] - '0')); x++) {
          dp[i + 1][smaller || x < (int)(S[i] - '0')][k + (x != 0)] +=
              dp[i][smaller][k];
        }
      }
    }
  }
  cout << dp[N][0][K] + dp[N][1][K] << endl;
  return 0;
}
