#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
void YesNo(T a) {
  cout << (a ? "Yes" : "No") << "\n";
}
template <class T>
void YESNO(T a) {
  cout << (a ? "YES" : "NO") << "\n";
}
void vout(vector<long long> &v) {
  for (long long i = 0; i < (v).size(); i++) cout << v[i] << " ";
  cout << "\n";
}
void vvout(vector<vector<long long> > &v) {
  for (long long i = 0; i < (v).size(); i++) vout(v[i]);
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long mypow(long long x, long long n, long long m) {
  if (n == 0) return 1;
  if (n % 2 == 0)
    return mypow(x * x % m, n / 2, m);
  else
    return x * mypow(x, n - 1, m) % m;
}
char digit(long long k, long long i) {
  string s = to_string(k);
  return s[s.size() - i];
}
void uniq(vector<long long> &v) {
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
}
long long ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
vector<long long> accum(vector<long long> v) {
  vector<long long> ret((v).size());
  ret[0] = v[0];
  for (long long i = 1; i < (v).size(); ++i) ret[i] = ret[i - 1] + v[i];
  return ret;
}
bool comp(pair<long long, long long> a, pair<long long, long long> b) {
  if (a.second != b.second)
    return a.second < b.second;
  else
    return a.first < b.first;
}
signed main() {
  string s;
  long long k;
  cin >> s >> k;
  if (k == 1) {
    long long ans = 9 * (s.size() - 1);
    ans += ctoi(s[0]);
    cout << ans << "\n";
  } else if (k == 2) {
    long long n = s.size();
    long long ans = (n - 1) * (n - 2) / 2 * 9 * 9;
    if (s[0] > '0') ans += (ctoi(s[0]) - 1) * (n - 1) * 9;
    if (s[1] > '0') ans += (n - 2) * 9;
    ans += (ctoi(s[1]));
    cout << ans << "\n";
  } else if (k == 3) {
    long long n = s.size();
    long long ans = (n - 1) * (n - 2) * (n - 3) / 6 * 9 * 9 * 9;
    if (s[0] > '0') ans += (ctoi(s[0]) - 1) * (n - 1) * (n - 2) / 2 * 9 * 9;
    if (s[1] > '0') ans += (n - 2) * (n - 3) / 2 * 9 * 9;
    if (s[1] > '0') ans += (ctoi(s[1]) - 1) * (n - 2) * 9;
    if (s[1] > '0' || s[2] > '0') ans += (n - 3) * 9;
    ans += ctoi(s[2]);
    cout << ans << "\n";
  }
  return 0;
}
