#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 21;
const long long INF = 1LL << 60;
const long long mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  int k;
  cin >> s >> k;
  if (s.size() < k) {
    cout << 0 << endl;
    return 0;
  }
  int n = s.size();
  if (k == 1) {
    long long ans = (n - 1) * 9 + (s[0] - '0');
    cout << max(ans, 0LL) << endl;
    return 0;
  } else if (k == 2) {
    long long ans = 0LL;
    ans = (n - 1) * (n - 2) / 2 * 81;
    ans += (s[0] - '0' - 1) * (n - 1) * 9;
    for (int i = 1; i < n; i++) {
      if (s[i] != '0') {
        ans += (n - 1 - i) * 9;
        ans += (s[i] - '0');
        break;
      }
    }
    cout << max(ans, 0LL) << endl;
  } else if (k == 3) {
    long long ans = 0LL;
    ans = (n - 1) * (n - 2) * (n - 3) / 6 * 81 * 9;
    ans += (s[0] - '0' - 1) * (n - 1) * (n - 2) / 2 * 81;
    ans += (n - 2) * (n - 3) / 2 * 81;
    int count = 0;
    for (int i = 1; i < n; i++) {
      if (count == 2) break;
      if (s[i] != '0') {
        if (count == 0) {
          ans += (s[1] - '0' - 1) * (n - 2) * 9;
        } else {
          ans += (n - 2 - i) * 9;
        }
        ans += (s[i] - '0');
        count++;
      }
    }
    cout << max(ans, 0LL) << endl;
  }
  return 0;
}
