#include <bits/stdc++.h>
using namespace std;
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;
template <class S, class T>
istream& operator>>(istream& is, pair<S, T>& p) {
  return is >> p.first >> p.second;
}
template <class T>
istream& operator>>(istream& is, vector<T>& xs) {
  for (auto& x : xs) is >> x;
  return is;
}
template <class S, class T>
ostream& operator<<(ostream& os, const pair<S, T>& p) {
  return os << p.first << " " << p.second;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& xs) {
  for (unsigned int i = 0; i < xs.size(); ++i) os << (i ? " " : "") << xs[i];
  return os;
}
template <class T>
void maxi(T& x, T y) {
  if (x < y) x = y;
}
template <class T>
void mini(T& x, T y) {
  if (x > y) x = y;
}
void debug(istringstream&) {}
template <char sep = ',', class Head, class... Tail>
void debug(istringstream& iss, Head&& head, Tail&&... tail) {
  string name;
  getline(iss, name, ',');
  cout << sep << name << "=" << head;
  debug(iss, forward<Tail>(tail)...);
}
void init_io(int argc, char* argv[]) {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
}
const double EPS = 1e-10;
const double PI = acos(-1.0);
const LL MOD = 1e9 + 7;
int main(int argc, char* argv[]) {
  init_io(argc, argv);
  string N;
  cin >> N;
  int K;
  cin >> K;
  int D = int((N).size());
  LL ans = 0;
  VI acc(D + 1);
  for (int i = (0); i < (D); ++i) acc[i + 1] = acc[i] + (N[i] == '0' ? 0 : 1);
  if (K == 1) {
    for (int i = (0); i < (D); ++i) {
      if (i)
        ans += 9;
      else
        ans += N[i] - '0';
    }
  } else if (K == 2) {
    for (int i = (0); i < (D); ++i)
      for (int j = (0); j < (i); ++j) {
        if (j)
          ans += 9 * 9;
        else {
          int d1 = N[j] - '0';
          int d2 = N[i] - '0';
          ans += 9 * (d1 - 1) + (acc[i] - acc[j + 1] ? 9 : d2);
        }
      }
  } else {
    for (int i = (0); i < (D); ++i)
      for (int j = (0); j < (i); ++j)
        for (int k = (0); k < (j); ++k) {
          if (k)
            ans += 9 * 9 * 9;
          else {
            int d1 = N[k] - '0';
            int d2 = N[j] - '0';
            int d3 = N[i] - '0';
            ans += 9 * 9 * (d1 - 1);
            if (acc[j] - acc[k + 1])
              ans += 9 * 9;
            else
              ans += 9 * (d2 - 1) + (acc[i] - acc[j + 1] ? 9 : d3);
          }
        }
  }
  cout << ans << endl;
  return 0;
}
