#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
ll g(string s) { return s.size() - 1; }
ll C2(ll n) { return n * (n - 1) / 2; }
ll C3(ll n) { return n * (n - 1) * (n - 2) / 6; }
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int k;
  cin >> k;
  if (s.size() < k) {
    cout << 0 << endl;
    return 0;
  }
  ll ans;
  switch (k) {
    case (1):
      cout << s[0] - '0' + 9 * g(s);
      break;
    case (2):
      ans = C2(g(s)) * 81 + (s[0] - '0' - 1) * g(s) * 9;
      ans += s[1] - '0' + (g(s) - 1) * 9;
      cout << ans << endl;
      break;
    case (3):
      ans = C3(g(s)) * 729 + (s[0] - '0' - 1) * C2(g(s)) * 81;
      ans += (max(s[1] - '0' - 1, 0)) * (g(s) - 1) * 9 + C2(g(s) - 1) * 81;
      ans += s[2] - '0' + (g(s) - 2) * 9;
      cout << ans << endl;
      break;
  }
}
