#include <bits/stdc++.h>
using namespace std;
const int64_t INF = (1LL << 62);
const double inf = pow(10, 10);
const long double pi = acosl(1);
const int64_t mod = 1000000007;
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
const int ddx[8] = {1, 0, -1, -1, -1, 0, 1, 1};
const int ddy[8] = {1, 1, 1, 0, -1, -1, -1, 0};
template <typename T>
T binomial(int64_t N, int64_t K) {
  if (K < 0 || N < K) return 0;
  T ret = 1;
  for (T i = 1; i <= K; ++i) {
    ret *= N--;
    ret /= i;
  }
  return ret;
}
int64_t k1(string n) {
  int64_t ans = 0;
  int64_t d1 = (n[0] - '0');
  ans += binomial<int64_t>((int64_t)n.size() - 1, 1) * 9;
  ans += d1;
  return ans;
}
int64_t k2(string n) {
  int64_t d2 = (n[0] - '0');
  int64_t ans = 0;
  ans += binomial<int64_t>((int64_t)n.size() - 1, 2) * 9 * 9;
  ans += (d2 - 1) * binomial<int64_t>((int64_t)n.size() - 1, 1) * 9;
  string n2;
  for (int i = 1; i < n.size(); i++) {
    n2.push_back(n[i]);
  }
  ans += k1(n2);
  return ans;
}
int main() {
  string n;
  cin >> n;
  int64_t k;
  cin >> k;
  int64_t ans = 0;
  if (k == 1) {
    cout << k1(n) << endl;
  }
  if (k == 2) {
    if (n.size() < 2u) {
      cout << 0 << endl;
      return 0;
    }
    cout << k2(n) << endl;
  }
  if (k == 3) {
    if (n.size() < 3) {
      cout << 0 << endl;
      return 0;
    }
    int64_t d3 = (n[0] - '0');
    ans += binomial<int64_t>((int64_t)n.size() - 1, 3) * 9 * 9 * 9;
    ans += (d3 - 1) * binomial<int64_t>((int64_t)n.size() - 1, 2) * 9 * 9;
    string n2;
    for (int i = 1; i < n.size(); i++) {
      n2.push_back(n[i]);
    }
    ans += k2(n2);
    cout << ans << endl;
  }
}
