#include <bits/stdc++.h>
using namespace std;
string N;
signed long long K;
signed long long len;
signed long long combination(signed long long n, signed long long k) {
  if (n < k) {
    return 0;
  }
  signed long long ans = 1;
  for (int i = 0; i < k; ++i) {
    ans *= n - i;
  }
  for (int i = 0; i < k; ++i) {
    ans /= i + 1;
  }
  return ans;
}
signed long long all9(signed long long n, signed long long k) {
  return (combination(n, k) * pow(9ll, k));
}
signed long long func(signed long long depth, signed long long k) {
  if (k == 0) {
    return 1;
  }
  if (depth == len) {
    return 0;
  }
  signed long long ret = 0;
  int num = N[depth] - '0';
  if (num > 1) {
    ret += all9(len - depth - 1, k - 1) * (num - 1);
  }
  if (num > 0) {
    ret += func(depth + 1, k - 1);
  }
  ret += all9(len - depth - 1, k);
  return (ret);
}
int main() {
  cin >> N >> K;
  len = N.size();
  cout << func(0, K) << endl;
  return 0;
  signed long long ans = 0;
  signed long long cnt = 0;
  for (int i = 0; i < len; ++i) {
    if (N[i] != '0') {
      ++cnt;
    }
  }
  if (cnt >= K) {
    ans += 1;
  }
  signed long long l = 0;
  while (K > 0) {
    cout << K << " " << len << endl;
    cout << ans << endl;
    if (len < K) {
      break;
    }
    if (N[l] == '0') {
      ++l;
      --len;
      continue;
    }
    signed long long s = N[l] - '0' - 1;
    ans += combination(len - 1, K - 1) * s * pow(9, K - 1);
    cout << ans << endl;
    for (signed long long i = 1; i <= len - K; ++i) {
      ans += combination(len - i - 1, K - 1) * 9 * pow(9, K - 1);
    }
    cout << ans << endl;
    --K;
    ++l;
    --len;
  }
  cout << ans << endl;
  return 0;
}
