#include <bits/stdc++.h>
using namespace std;
template <class T>
void debug(T itr1, T itr2) {
  auto now = itr1;
  while (now < itr2) {
    cout << *now << " ";
    now++;
  }
  cout << endl;
}
const long long MOD = pow(10, 9) + 7;
const long long LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;
vector<long long> fac;
void c_fac(int x = pow(10, 6) + 10) {
  fac.resize(x, true);
  for (int i = (int)0; i < (int)x; i++) fac[i] = i ? (fac[i - 1] * i) % MOD : 1;
}
long long inv(long long a, long long m = MOD) {
  long long b = m, x = 1, y = 0;
  while (b != 0) {
    int d = a / b;
    a -= b * d;
    swap(a, b);
    x -= y * d;
    swap(x, y);
  }
  return (x + m) % m;
}
long long nck(long long n, long long k) {
  return fac[n] * inv(fac[k] * fac[n - k] % MOD) % MOD;
}
long long gcd(long long a, long long b) {
  if (a < b) swap(a, b);
  return b == 0 ? a : gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
int main() {
  string N;
  cin >> N;
  int l = N.size();
  int K;
  cin >> K;
  string zero;
  for (int i = (int)0; i < (int)l; i++) zero += '0';
  vector<int> nz;
  for (int i = (int)0; i < (int)l; i++)
    if (N[i] != '0') nz.push_back(i);
  long long result = 0;
  if (K == 1)
    result = (N[0] - '0') + (l - 1) * 9;
  else if (K == 2) {
    for (int i = (int)1; i < (int)l; i++) {
      for (int in = (int)1; in < (int)10; in++) {
        string tmp = zero;
        string ln = "";
        ln += ('0' + in);
        tmp.replace(0, 1, N.substr(0, 1));
        tmp.replace(i, 1, ln);
        if (tmp <= N) result++;
      }
    }
    result += (N[0] - '1') * ((l - 1) * 9);
    result += (l - 1) * (l - 2) / 2 * 9 * 9;
  } else if (K == 3) {
    for (int i = (int)1; i < (int)l; i++)
      for (int j = (int)i + 1; j < (int)l; j++) {
        for (int in = (int)1; in < (int)10; in++)
          for (int jn = (int)1; jn < (int)10; jn++) {
            string tmp = zero;
            string ln = "", rn = "";
            ln += ('0' + in);
            rn += ('0' + rn);
            tmp.replace(0, 1, N.substr(0, 1));
            tmp.replace(i, 1, ln);
            tmp.replace(j, 1, rn);
            if (tmp <= N) result++;
          }
      }
    result += (N[0] - '1') * (l - 1) * (l - 2) / 2 * 9 * 9;
    result += (l - 1) * (l - 2) * (l - 3) / 6 * 9 * 9 * 9;
  }
  cout << result << endl;
  return 0;
}
