#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();
  string t = "";
  bool notzero = false;
  for (int i = 0; i < (int)(n - 1); i++) {
    if (notzero)
      t += s.at(i + 1);
    else if (s.at(i + 1) != '0') {
      notzero = true;
      t += s.at(i + 1);
    }
  }
  int m = t.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');
    if (m > 0) {
      ans += (int)(t.at(0) - '0');
      ans += (m - 1) * 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');
    if (m > 1) {
      string u = "";
      bool nozero = false;
      for (int i = 0; i < (int)(m - 1); i++) {
        if (nozero)
          u += t.at(i + 1);
        else if (t.at(i + 1) != '0') {
          nozero = true;
          u += t.at(i + 1);
        }
      }
      int l = u.size();
      if (l > 0) {
        ans += (int)(u.at(0) - '0');
        ans += (l - 1) * 9;
      }
      ans += (int)(t.at(0) - '1') * (m - 1) * 9;
    }
    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;
}
