#include <bits/stdc++.h>
using namespace std;
char s[105];
long long K, a[105];
const int d[] = {1, 9, 81, 729};
long long C(long long x, long long k) {
  if (k == 1)
    return x;
  else if (k == 2)
    return x * (x - 1) / 2;
  else
    return x * (x - 1) * (x - 2) / 6;
}
long long solve(int now, int k, bool f) {
  if (now < k || (!now && k)) return 0;
  if (!k) return 1;
  if (f) {
    return C(now, k) * d[k];
  }
  long long ret = solve(now - 1, k, 1);
  if (a[now])
    ret += solve(now - 1, k - 1, f) + solve(now - 1, k - 1, 1) * (a[now] - 1);
  return ret;
}
int main() {
  scanf("%s", s + 1);
  int n = strlen(s + 1);
  for (int i = 1; i <= n; i++) a[i] = s[i] - '0';
  reverse(a + 1, a + n + 1);
  cin >> K;
  printf("%lld\n", solve(n, K, 0));
  return 0;
}
