#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
const ll MOD = 1000000007;
const int INFI = 1000000000;
const ll INFL = (1LL << 60);
int main() {
  string N;
  cin >> N;
  ll K;
  cin >> K;
  ll n = N.length(), ans = 0;
  if (K == 1)
    ans += 9 * (n - 1) + (ll)(N.front() - '0');
  else if (K == 2) {
    ans +=
        81 * (n - 2) * (n - 1) / 2 + ((ll)(N.front() - '0') - 1) * 9 * (n - 1);
    for (int i = 1; i < (int)(n); i++) {
      if (N.at(i) == '0')
        continue;
      else {
        ans += (ll)(N.at(i) - '0') + 9 * (n - 1 - i);
        break;
      }
    }
  } else if (K == 3) {
    for (int i = 3; i < (int)(n); i++) ans += 729 * (i - 1) * (i - 2) / 2;
    ans += ((ll)(N.front() - '0') - 1) * (n - 1) * (n - 2) / 2 * 81;
    string zero, N_sub = N.substr(1, n - 1);
    for (int i = 0; i < (int)(n - 1); i++) zero += "0";
    for (int i = 0; i < (int)(n - 2); i++) {
      for (int j = i + 1; j < (int)(n - 1); j++) {
        string zero_tmp = zero;
        for (int k = 1; k < (int)(10); k++) {
          zero_tmp.at(i) = k;
          for (int l = 1; l < (int)(10); l++) {
            zero_tmp.at(j) = l;
            if (zero_tmp <= N_sub) ans++;
          }
        }
      }
    }
  }
  cout << ans << endl;
}
