#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i32 = int32_t;
using i64 = int64_t;
constexpr char newl = '\n';
constexpr double eps = 1e-10;
template <typename T1, typename T2>
inline void chmin(T1& a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1& a, T2 b) {
  if (a < b) a = b;
}
template <class T>
void Print(vector<T> v) {
  for (int i = (0); i < (v.size()); i++) {
    cout << v[i] << ' ';
  }
  cout << newl;
}
i64 ncr(i64 n, i64 r) {
  if (n < r) return 0;
  i64 a = 1, b = 1;
  int im = r;
  for (int i = (0); i < (im); i++) {
    a *= n;
    b *= r;
    n--;
    r--;
  }
  return a / b;
}
i64 calc(string N, int K) {
  if (K == 0) return 1;
  if (N.size() == 0) return 0;
  i64 result = 0;
  int n = N.front() - '0';
  result += ncr(N.size() - 1, K) * pow(9, K);
  if (n > 0) {
    result += (n - 1) * ncr(N.size() - 1, K - 1) * pow(9, K - 1);
  }
  if (n > 0) {
    result += calc(N.substr(1, N.size() - 1), K - 1);
  }
  return result;
}
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  string N;
  int K;
  cin >> N >> K;
  cout << calc(N, K);
}
