#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m = 0, k, a[4] = {0, 9, 81, 729};
  string s;
  cin >> s >> k;
  n = s.size();
  if (n < k) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < k; i++) m = 10 * m + s[i] - '0';
  long long ans = 0, num = 0;
  int i;
  if (k == 1) {
    for (i = 1; i <= n - k; i++) {
      ans += a[k];
    }
    for (m++; m < pow(10, k); m++) {
      num++;
    }
    ans += (a[k] - num);
  } else if (k == 2) {
    for (i = 0; i < n - k; i++) ans += a[k] * (i + 1);
    int t = 1;
    while (s[t] == '0' && t < n) t++;
    for (int j = 11; j < 100; j++) {
      int a = (j / 10) % 10, b = j % 10;
      if (a && b) {
        if (j <= m)
          ans += i + 1;
        else if (a <= s[0] - '0' && t < n) {
          if (s[t] - '0' >= b)
            ans += n - t;
          else
            ans += n - t - 1;
        } else
          break;
      }
    }
  } else {
    for (i = 0; i < n - k; i++) ans += a[k] * ((i + 2) * (i + 1) / 2);
    int t = 1;
    while (s[t] == '0' && t < n) t++;
    int r = t + 1;
    while (s[r] == '0' && r < n) r++;
    for (int j = 111; j < 1000; j++) {
      int a = (j / 100) % 10, b = (j / 10) % 10, c = j % 10;
      if (a && b && c) {
        if (j <= m)
          ans += (i + 2) * (i + 1) / 2;
        else if (a <= s[0] - '0' && t < n - 1) {
          if (s[t] - '0' >= b)
            ans += n - t;
          else
            ans += n - t - 1;
        } else
          break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
