#include <bits/stdc++.h>
using namespace std;
template <class Type_a, class Type_b>
void chmax(Type_a &a, const Type_b &b) {
  if (a < b) a = b;
}
template <class Type_a, class Type_b>
void chmin(Type_a &a, const Type_b &b) {
  if (a > b) a = b;
}
template <class Type>
Type igcd(Type x, Type y) {
  if (x == 0 || y == 0) return (x > y) ? x : y;
  return (y % x) ? igcd(y % x, x) : x;
}
template <class Type>
Type ilcm(Type x, Type y) {
  return x / igcd(x, y) * y;
}
template <class Type>
void line(const Type &a) {
  int cnt = 0;
  for (const auto &elem : a) {
    if (cnt++) cout << ' ';
    cout << elem;
  }
  cout << endl;
}
template <class Type, class Type_k>
Type nCk(Type n, Type_k k) {
  if (n < k) return 0;
  if (n < 0 or k < 0) return 0;
  Type res = 1;
  for (Type i = 0; i < k; ++i) res *= n - i, res /= i + 1;
  return res;
}
int main() {
  string s;
  int k;
  cin >> s >> k;
  long long ans = 0;
  int tmp = s.size();
  if (k == 1) {
    ans = 9 * (tmp - 1);
    ans += s[0] - '0';
  } else if (k == 2) {
    if (tmp < 2) {
      cout << 0 << endl;
      return 0;
    }
    ans = nCk(tmp - 1, 2) * pow(9, 2);
    ans += 9 * (tmp - 1) * (s[0] - '0' - 1);
    ans += 9 * (tmp - 2);
    ans += s[1] - '0';
  } else if (k == 3) {
    if (tmp < 3) {
      cout << 0 << endl;
      return 0;
    }
    ans = nCk(tmp - 1, 3) * pow(9, 3);
    ans += nCk(tmp - 1, 2) * pow(9, 2) * (s[0] - '0' - 1);
    ans += nCk(tmp - 2, 2) * pow(9, 2);
    ans += (s[1] - '0') * (tmp - 2) * 9;
  }
  cout << ans << endl;
}
