#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T gcd(T a, T b) {
  if (b) return gcd(b, a % b);
  return a;
}
template <typename T>
inline T ext_gcd(T a, T b, T& x, T& y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  T x1, y1;
  T g = ext_gcd(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return g;
}
long long f1(string n, long long N) {
  if (N == 0) return n[0] - '0';
  string x = "";
  x.resize(N);
  for (long long(i) = 0; i < N; i++) x[i] = n[i];
  return 9 + f1(x, N - 1);
}
long long f2(string n, long long N) {
  if (N < 1) return 0;
  string x = "";
  x.resize(N);
  for (long long(i) = 0; i < N; i++) x[i] = '9';
  long long res1 = (n[0] - '0' - 1) * f1(x, N - 1) + f2(x, N - 1);
  bool found = false;
  x = "";
  for (long long(i) = 1; i < N + 1; i++) {
    if (n[i] != '0' || found) {
      x += n[i];
      found = true;
    }
  }
  long long res2 = f1(x, (long long)x.size() - 1);
  return res1 + res2;
}
long long f3(string n, long long N) {
  if (N < 2) return 0;
  string x = "";
  x.resize(N);
  for (long long(i) = 0; i < N; i++) x[i] = '9';
  long long res1 = (n[0] - '0' - 1) * f2(x, N - 1) + f3(x, N - 1);
  bool found = false;
  x = "";
  for (long long(i) = 1; i < N + 1; i++) {
    if (n[i] != '0' || found) {
      x += n[i];
      found = true;
    }
  }
  long long res2 = f2(x, (long long)x.size() - 1);
  return res1 + res2;
}
int main() {
  string n;
  long long k;
  cin >> n >> k;
  long long N = n.size() - 1;
  if (k == 1)
    cout << f1(n, N) << '\n';
  else if (k == 2)
    cout << f2(n, N) << '\n';
  else
    cout << f3(n, N) << '\n';
}
