#include <bits/stdc++.h>
using namespace std;
long long INF = LLONG_MAX;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin >> s;
  int k;
  cin >> k;
  long long ans = 0;
  long long n = s.length();
  if (k > n) {
    cout << 0 << endl;
    return 0;
  }
  if (k == 1) {
    long long mx = s[0] - '0';
    ans = (n - 1) * 9 + mx;
  } else if (k == 2) {
    long long mx1 = s[0] - '0';
    long long mx2 = s[1] - '0';
    ans += mx2;
    ans += (n - 2) * 9;
    ans += (mx1 - 1) * 9 * (n - 1);
    ans += ((n - 2) * (n - 1) * 81) / 2;
  } else {
    long long mx1 = s[0] - '0';
    long long mx2 = s[1] - '0';
    long long mx3 = s[2] - '0';
    long long cur = (n - 1) * (n - 2) * 81;
    cur /= 2;
    ans += cur;
    cur = (mx1 - 1) * (n - 1) * (n - 2) * 81;
    cur /= 2;
    ans += cur;
    cur = (n - 1) * (n - 2) * (n - 3) * 729;
    cur /= 6;
    ans += cur;
  }
  cout << ans << endl;
}
