#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  string s;
  cin >> s;
  long long k;
  cin >> k;
  long long n = s.size();
  if (n < k) {
    cout << 0;
    return 0;
  }
  if (n < 7) {
    long long no = stoi(s);
    long long ans = 0;
    for (long long i = 1; i <= no; i++) {
      string p = to_string(i);
      long long cnt = 0;
      for (auto x : p)
        if (x != '0') cnt++;
      if (cnt == k) ans++;
    }
    cout << ans << endl;
    return 0;
  }
  long long ans = 0;
  if (k == 3) {
    for (long long i = k; i <= n - 1; i++) {
      ans += 9 * 81 * (i - 1) * (i - 2) / 2;
    }
    for (long long i = 1; i < s[0] - '0'; i++)
      ans += 81 * (n - 1) * (n - 2) / 2;
    for (long long i = 1; i < n - 1; i++) {
      for (long long j = 1; j <= s[i] - '0'; j++) {
        if (j < s[i] - '0')
          ans += 9 * (n - i - 1);
        else {
          for (long long k = i + 1; k < n; k++) {
            ans += s[k] - '0';
          }
        }
      }
    }
    cout << ans << endl;
  } else if (k == 2) {
    for (long long i = k; i <= n - 1; i++) {
      ans += 81 * (i - 1);
    }
    for (long long i = 1; i < s[0] - '0'; i++) ans += 9 * (n - 1);
    for (long long k = 1; k < n; k++) {
      ans += s[k] - '0';
    }
    cout << ans << endl;
  } else {
    for (long long i = 0; i < n; i++) {
      ans += (s[i] - '0');
    }
    cout << ans << endl;
  }
  return 0;
}
