#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 = 9 - (s[0] - '0');
    long long mx2 = 9 - (s[1] - '0');
    ans += n * (n - 1) * 81 / 2;
    ans -= mx1 * (n - 1) * 9;
    ans -= mx2;
  } else {
    long long mx1 = 9 - (s[0] - '0');
    long long mx2 = 9 - (s[1] - '0');
    long long mx3 = 9 - (s[2] - '0');
    ans += n * (n - 1) * (n - 2) * 729 / 6;
    ans -= mx1 * (n - 1) * (n - 2) * 81 / 2;
    ans -= mx1 * mx2;
  }
  cout << ans << endl;
}
