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