#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int in() {
  int x;
  cin >> x;
  return x;
}
long long lin() {
  long long x;
  cin >> x;
  return x;
}
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>
inline void print(pair<T, T> p) {
  cout << "(" << p.first << "," << p.second << ") ";
}
template <class T>
inline void print(vector<pair<T, T>> v) {
  for (auto e : v) print(e);
  cout << endl;
}
template <class T>
inline void print(T v) {
  for (auto e : v) cout << e << " ";
  cout << endl;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x;
  return is;
}
const long long INF = 1e9 + 100;
int main() {
  string n;
  long long k;
  cin >> n >> k;
  long long m = n.length();
  vector<long long> t(m);
  for (long long i = 0; i < m; i++) {
    t[i] = n[i] - '0';
  }
  if (k == 1) {
    cout << 9 * (m - 1) + t[0] << endl;
    ;
  } else if (k == 2) {
    long long s = 0;
    if (m == 2) {
      s += t[1];
    } else {
      s += t[1] + 9 * (m - 2);
    }
    s += (t[0] - 1) * 9 * (m - 1);
    m--;
    while (m >= 2) {
      s += 9 * 9 * (m - 1);
      m--;
    }
    cout << s << endl;
  } else {
    long long s = 0;
    long long p = m;
    s += ((t[0] - 1) * (p - 1) * (p - 2) * 9 * 9 / 2);
    s += t[2] + 9 * (m - 3);
    s += (t[2] - 1) * 9 * (m - 2);
    long long q = m;
    m -= 2;
    while (m >= 2) {
      s += 9 * 9 * (m - 1);
      m--;
    }
    q--;
    while (q >= 3) {
      s += 9 * 9 * 9 * (q - 1) * (q - 2) / 2;
      q--;
    }
    cout << s << endl;
  }
  return 0;
}
