#include <bits/stdc++.h>
using namespace std;
long long power(long long x, long long y) {
  int res = 1;
  x = x % 1000000007;
  while (y > 0) {
    if (y & 1) res = (res * x) % 1000000007;
    y = y >> 1;
    x = (x * x) % 1000000007;
  }
  return res;
}
long long bc(int n, int k) {
  long long C[k + 1];
  memset(C, 0, sizeof(C));
  C[0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = min(i, k); j > 0; j--) C[j] = C[j] + C[j - 1];
  }
  return C[k];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string s;
  cin >> s;
  int k;
  cin >> k;
  int l = s.size();
  if (l < k) {
    cout << 0;
    return 0;
  }
  long long ans = pow(9, k);
  if (l == k) ans = 0;
  for (int i = k + 1; i <= l - 1; i++) {
    ans += (bc(i - 1, k - 1) * pow(9, k));
  }
  ans += (((s[0] - '0') - 1) * bc(l - 1, k - 1) * pow(9, k - 1));
  ans += (bc(l - k, k - 1) * pow(9, k - 1));
  long long p = 0;
  if (k == 1)
    p = 0;
  else if (k == 2)
    p = s[1] - '0';
  else
    p = (s[1] - '0' - 1) * 9 + (s[2] - '0');
  cout << ans + p;
}
