#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
signed main() {
  ll n, k, ans = 0;
  string s;
  cin >> s >> k;
  if (k == 1) {
    cout << (ll)(s[0] - '0') + 9 * (s.size() - 1) << endl;
  }
  if (k == 2) {
    ll x = 9 * 9 * (s.size() - 1) * (s.size() - 2) / 2;
    ll y = ((ll)(s[0] - '0') - 1) * 9 * (s.size() - 1);
    cout << x + y + (ll)(s[1] - '0') + 9 * (s.size() - 2) << endl;
  }
  if (k == 3) {
    ll x = 9 * 9 * 9 * (s.size() - 1) * (s.size() - 2) * (s.size() - 3) / 3 / 2;
    x += ((ll)(s[0] - '0') - 1) * 9 * 9 * (s.size() - 1) * (s.size() - 2) / 2;
    x += 9 * max((ll)(s[1] - '0') - 1, (ll)0) * (s.size() - 2) +
         (int)(s[2] - '0');
    x += 9 * 9 * (s.size() - 2) * (s.size() - 3) / 2;
    if ((ll)(s[2] - '0') != 0) {
      x += 9 * (s.size() - 3);
    }
    cout << x << endl;
  }
  return 0;
}
