#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  int k;
  cin >> k;
  int f = s[0] - '0';
  int n = s.length();
  if (k == 1) {
    long long ans = 9 * (n - 1) + f;
    cout << ans << "\n";
  } else if (k == 2) {
    long long ans = (n - 2) * (n - 1) * 81 / 2;
    ans += (f - 1) * 9 * (n - 1);
    int ss = 1;
    while (ss < n && s[ss] == 0) ss++;
    if (ss != n) ans += s[ss] - '0';
    for (int i = ss + 1; i < n; i++) {
      ans += 9;
    }
    cout << ans << "\n";
  } else {
    long long ans = (n - 3) * (n - 2) * (n - 1) * 9 * 9 * 9 / 6;
    ans += (f - 1) * (n - 1) * (n - 2) * 81 / 2;
    int ss = 1;
    while (ss < n && s[ss] == 0) ss++;
    if (ss != n) ans += (n - 1 - ss) * (n - 2 - ss) * 81 / 2;
    ans += (s[ss] - '0' - 1) * 9 * (n - 1 - ss);
    int sss = ss + 1;
    while (sss < n && s[sss] == 0) sss++;
    if (sss != n) ans += s[sss] - '0';
    for (int i = sss + 1; i < n; i++) ans += 9;
    cout << ans << "\n";
  }
}
