#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pil = pair<int, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
template <typename T>
inline istream& operator>>(istream& i, vector<T>& v) {
  for (int j = 0; j < (v.size()); ++j) i >> v[j];
  return i;
}
template <typename T>
string join(const vector<T>& v) {
  stringstream s;
  for (int i = 0; i < (v.size()); ++i) s << ' ' << v[i];
  return s.str().substr(1);
}
template <typename T>
inline ostream& operator<<(ostream& o, const vector<T>& v) {
  if (v.size()) o << join(v);
  return o;
}
template <typename T1, typename T2>
inline istream& operator>>(istream& i, pair<T1, T2>& v) {
  return i >> v.first >> v.second;
}
template <typename T1, typename T2>
inline ostream& operator<<(ostream& o, const pair<T1, T2>& v) {
  return o << v.first << "," << v.second;
}
const double eps = 1e-6;
const ll LINF = 100200300400500600ll;
const int INF = 1001001001;
template <class T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  } else
    return 0;
}
template <class T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  } else
    return 0;
}
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {-1, 0, 1, 0};
ll binomial(int N, int K) {
  if (K < 0 || N < K) return 0;
  ll ret = 1;
  for (ll i = 1; i <= K; ++i) {
    ret *= N--;
    ret /= i;
  }
  return ret;
}
void Main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  if (s.length() >= k) {
    ll ans = binomial(s.length(), k);
    for (int i = 0; i < (k); ++i) ans *= 9;
    if (k == 1) {
      string t(s.length(), '0');
      for (int i = 1; i < 10; ++i) {
        t[0] = i + '0';
        if (s < t) ans--;
      }
    } else if (k == 2) {
      for (int i = 1; i < 10; ++i) {
        for (int j = 1; j < 10; ++j) {
          for (int k = 0; k < (s.length() - 1); ++k) {
            string t(s.length(), '0');
            t[0] = i + '0';
            t[k + 1] = j + '0';
            if (s < t) ans--;
          }
        }
      }
    } else {
      for (int i = 1; i < 10; ++i) {
        for (int j = 1; j < 10; ++j) {
          for (int k = 1; k < 10; ++k) {
            for (int p1 = 1; p1 < s.length(); ++p1) {
              for (int p2 = p1 + 1; p2 < s.length(); ++p2) {
                string t(s.length(), '0');
                t[0] = i;
                t[p1] = j + '0';
                t[p2] = k + '0';
                if (s < t) ans--;
              }
            }
          }
        }
      }
    }
    cout << ans << endl;
  } else {
    cout << 0 << endl;
    return;
  }
}
signed main(int argc, char** argv) {
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  ;
  ifstream iofi;
  if (argc > 1) {
    iofi.open(argv[1]);
    std::cin.rdbuf(iofi.rdbuf());
  };
  int loop = 1;
  if (argc > 2) loop = stoi(argv[2]);
  for (int i = 0; i < (loop); ++i) Main();
}
