#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const double EPS = 1e-9;
const long long INF = (1 << 30) - 1;
const long long INFLL = (1LL << 62) - 1;
inline long long in() {
  long long x;
  scanf("%d", &x);
  return x;
}
template <typename tuple<long long, long long, long long> >
inline long long suma(
    const vector<tuple<long long, long long, long long> >& a) {
  long long res(0);
  for (auto&& x : a) res += x;
  return res;
}
template <class tuple<long long, long long, long long> >
inline bool chmax(tuple<long long, long long, long long>& a,
                  tuple<long long, long long, long long> b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
} template <class tuple<long long, long long, long long> >
inline bool chmin(tuple<long long, long long, long long>& a,
                  tuple<long long, long long, long long> b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
} long long dp[1050][2][4];
signed main() {
  string N;
  long long K;
  cin >> N >> K;
  long long n = (long long)(N).size();
  dp[0][0][0] = 1;
  for (long long i = (0); i < (n); ++i) {
    for (long long j = (0); j < (K + 1); ++j) {
      for (long long dig = (0); dig < (10); ++dig)
        dp[i + 1][1][dig != 0 ? j + 1 : j] += dp[i][1][j];
      for (long long dig = (0); dig < (N[i] - '0'); ++dig)
        dp[i + 1][1][dig != 0 ? j + 1 : j] += dp[i][0][j];
      dp[i + 1][0][N[i] - '0' != 0 ? j + 1 : j] += dp[i][0][j];
    }
  }
  long long ans = dp[n][0][K] + dp[n][1][K] - dp[n][0][K - 1] - dp[n][1][K - 1];
  cout << ans << endl;
  return 0;
}
