#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long gcd(long long a, long long b) {
  while (min(a, b) > 0) {
    if (a < b) swap(a, b);
    a = a % b;
  }
  return max(a, b);
}
long long dx[] = {0, 1, 0, -1};
long long dy[] = {1, 0, -1, 0};
struct Edge {
  long long to, weight;
};
long long com(long long n, long long k) {
  if (n == 0)
    return 1;
  else if (k == 1)
    return n;
  else if (k == 2)
    return n * (n - 1) / 2;
  else if (k == 3)
    return n * (n - 1) * (n - 2) / 6;
  else if (k == 0)
    return 1;
}
signed main() {
  string n;
  long long k;
  cin >> n >> k;
  long long keta = n.length();
  long long ans = 0;
  if (k < keta)
    for (long long i = (k); i <= (keta - 1); i++) {
      ans += com(i - 1, k - 1) * pow(9, k);
    }
  long long top1 = n[0] - '0';
  long long top2 = n[1] - '0';
  long long top3 = n[2] - '0';
  if (k == 1) {
    ans += top1;
  } else if (k == 2) {
    ans += 9 * (keta - 1) * (top1 - 1);
    if (keta > 2) ans += com(keta - 2, 1) * 9;
    ans += top2;
  } else if (k == 3) {
    ans += (top1 - 1) * com(keta - 1, 2) * 9 * 9;
    if (keta > 2) ans += com(keta - 2, 2) * 9 * 9;
    ans += (top2 - 1) * (keta - 2) * 9;
    if (keta > 3) ans += (keta - 3) * 9;
    ans += top3;
  }
  cout << ans << endl;
  return 0;
}
