#include <bits/stdc++.h>
const long long INF = LLONG_MAX / 2;
const long long N = 2e5 + 1;
using namespace std;
long long pow1(long long n, long long p) {
  if (p == 0) return 1;
  long long x = pow1(n, p / 2);
  x = (x * x);
  if (p % 2 == 0)
    return x;
  else
    return (x * n);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  t = 1;
  while (t--) {
    string s;
    std::cin >> s;
    long long k, x;
    std::cin >> k;
    long long n = s.length(), sum;
    long long d = n;
    if (k == 1) {
      sum = (d - 1) * 9;
    } else {
      if (k == 2)
        sum = ((d - 1) * 9 * 9 * (d - 2)) / 2;
      else
        sum = ((d - 3) * (d - 1) * 9 * 9 * (d - 2)) / 6;
    }
    long long count = 0;
    for (long long i = 0; i < n; i++) {
      count++;
      long long c = s[i] - 48, y = 0;
      k--;
      d--;
      if (c < 0) {
        k++;
        if (k < 0) break;
        continue;
      }
      if (c == 0 && d != n - 1) c = 1, k++, y = 1;
      if (k < 0) break;
      if (k == 1) {
        sum = sum + c * (d)*9;
      } else {
        if (k == 2)
          sum = sum + c * (((d)*9 * 9 * (d - 1)) / 2);
        else
          sum += c;
      }
      if (y == 1) k--;
    }
    sum++;
    std::cout << sum << "\n";
  }
}
