#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string n;
  cin >> n;
  long long k;
  long long c = 0;
  cin >> k;
  long long ans = 0;
  long long t;
  t = n.size();
  if (k == 1) {
    cout << (t - 1) * 9 + n[0] - '0' << endl;
  } else if (k == 2) {
    if (t < 2) {
      cout << 0 << endl;
      return 0;
    }
    ans += (t - 1) * (t - 2) / 2 * long long(9 * 9);
    ans += long long(n[0] - '0' - 1) * (t - 1) * 9;
    t--;
    ans += (t - 1) * 9 + n[1] - '0';
    cout << ans << endl;
  } else if (k == 3) {
    if (t < 3) {
      cout << 0 << endl;
      return 0;
    }
    ans += (t - 1) * (t - 2) * (t - 3) / long long(6) * long long(9 * 9 * 9);
    ans += long long(n[0] - '0' - 1) * (t - 1) * (t - 2) / 2 * long long(9 * 9);
    t--;
    ans += (t - 1) * (t - 2) / 2 * long long(9 * 9);
    ans += long long(n[1] - '0' - 1) * (t - 1) * 9;
    t--;
    ans += (t - 1) * 9 + n[2] - '0';
    cout << ans << endl;
  }
}
