#include <bits/stdc++.h>
using namespace std;
void main_sub(void);
int main(int argc, char* argv[]) {
  main_sub();
  return 0;
}
using i64 = int64_t;
constexpr i64 INF = (1 << 30);
constexpr i64 INFL = (1LL << 62);
constexpr i64 MOD = 1000000007;
void main_sub(void) {
  string s;
  cin >> s;
  i64 k;
  cin >> k;
  i64 top = s[0] - '0';
  i64 n = s.size();
  if (k == 1) {
    cout << top + (n - 1) * 9 << endl;
    return;
  } else if (k == 2) {
    if (n < 2) {
      cout << 0 << endl;
      return;
    } else if (n == 2) {
      cout << (top - 1) * 9 + (i64)(s[1] - '0') << endl;
      return;
    }
    i64 ans = 0;
    ans += (n - 1) * (n - 2) / 2 * 9 * 9;
    ans += (top - 1) * (n - 1) * 9;
    ans += (n - 2) * 9;
    ans += (i64)(s[1] - '0');
    cout << ans << endl;
  } else {
    if (n < 3) {
      cout << 0 << endl;
      return;
    }
    i64 ans = 0;
    ans += (n - 1) * (n - 2) * (n - 3) / 6 * 9 * 9 * 9;
    ans += (top - 1) * (n - 1) * (n - 2) / 2 * 9 * 9;
    ans += ((i64)(s[1] - '0') - 1) * (n - 2) * 9;
    ans += (n - 2) * (n - 3) / 2 * 9 * 9;
    ans += ((i64)(s[2] - '0') - 1);
    ans += (n - 3) * 9;
    ++ans;
    cout << ans << endl;
  }
  return;
}
