#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 9999999999;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline T powerM(T a, T b) {
  if (b == 0) return 1;
  T tmp = powerM(a, b / 2);
  if (b % 2 == 0)
    return tmp * tmp % MOD;
  else
    return tmp * tmp % MOD * a % MOD;
}
int main() {
  string s;
  cin >> s;
  int n = s.size();
  int k;
  cin >> k;
  ll ans = 0;
  int char1 = (int)(s.at(0) - '0');
  if (k == 1) {
    ans = char1 + (n - 1) * 9;
  } else if (k == 2 && n == 1) {
    ans = 0;
  } else if (k == 2 && n == 2) {
    ans = (int)(s.at(1) - '0') + (char1 - 1) * 9;
  } else if (k == 2) {
    int char2 = (int)(s.at(1) - '0');
    ans = 1 * 1 * char2;
    ans += 1 * (n - 2) * 9;
    ans += (char1 - 1) * (n - 1) * 9;
    int bufs = n - 1;
    while (bufs > 1) {
      ans += 9 * (bufs - 1) * 9;
      bufs--;
    }
  } else if (k == 3 && n == 1) {
    ans = 0;
  } else if (k == 3 && n == 2) {
    ans = 0;
  } else {
    int char2 = (int)(s.at(1) - '0');
    int char3 = (int)(s.at(2) - '0');
    ans = 1 * 1 * (char2 * char3);
    ans += 1 * (n - 3) * (char2 * 9);
    ans += 1 * (n - 3) * (char3 * 9);
    ans += 1 * (n - 3) * (n - 4) / 2 * 81;
    ans += (char1 - 1) * (n - 1) * (n - 2) / 2 * 81;
    int bufs = n - 1;
    while (bufs > 2) {
      ans += 9 * (bufs - 1) * (bufs - 2) / 2 * 81;
      bufs--;
    }
  }
  cout << ans << endl;
}
