#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <class T>
struct rge {
  T b, e;
};
template <class T>
rge<T> range(T i, T j) {
  return rge<T>{i, j};
}
template <class T>
auto dud(T *x) -> decltype(cerr << *x, 0);
template <class T>
char dud(...);
struct debug {
  template <class T>
  debug &operator<<(const T &) {
    return *this;
  }
};
string num;
int k;
long long mem[105][4][2];
int done[105][4][2], timer = 0;
int dp(int i, int k, bool small) {
  if (i == (int)num.size()) return k == ::k;
  long long &ans = mem[i][k][small];
  if (done[i][k][small] != timer) {
    done[i][k][small] = timer;
    ans = 0LL;
    int hi = small ? 9 : num[i] - '0';
    for (auto d = (0) - ((0) > (hi + 1)); d != hi + 1 - ((0) > (hi + 1));
         d += 1 - 2 * ((0) > (hi + 1))) {
      int nk = (k + (d != 0));
      if (nk > ::k) continue;
      ans += dp(i + 1, nk, small | (d < hi));
    }
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  while (cin >> num >> k) {
    ++timer;
    cout << dp(0, 0, 0) << '\n';
  }
  return 0;
}
