#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = {0, -1, 1, 0};
const ll dy[4] = {-1, 0, 0, 1};
const int INF = 1e9 + 7;
int gcd(int x, int y) {
  if (x < y) swap(x, y);
  if (y == 0) return x;
  return gcd(y, x % y);
}
void mul(ll a, ll b) { a = a * b % INF; }
using Graph = vector<vector<int>>;
int main() {
  string N;
  cin >> N;
  int n = N.size();
  int K;
  cin >> K;
  ll dp[110][2][4];
  for (ll i = (0); i <= (110 - 1); i++) {
    for (ll j = (0); j <= (2 - 1); j++) {
      for (ll k = (0); k <= (4 - 1); k++) {
        dp[i][j][k] = 0;
      }
    }
  }
  dp[0][0][0] = 1;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 2; ++j) {
      for (int k = 0; k <= K; ++k) {
        int x;
        x = j ? 9 : N[i] - '0';
        for (int d = 0; d <= x; ++d) {
          if (d != 0) {
            dp[i + 1][j || (d < x)][k + 1] += dp[i][j][k];
          } else {
            dp[i + 1][j || (d < x)][k] += dp[i][j][k];
          }
        }
      }
    }
  }
  cout << dp[n][0][K] + dp[n][1][K] << endl;
  return 0;
}
