#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 200000 + 5;
int a[N];
long long c(long long n, long long m) {
  long long t1 = max(n - m, m), t2 = min(n - m, m);
  if (n < m) return 0;
  long long z = 1;
  for (int i = n; i > t1; i--) z *= i;
  for (int i = 2; i <= t2; i++) z /= i;
  return z;
}
int main() {
  string n;
  cin >> n;
  int k;
  cin >> k;
  long long len = n.length();
  if (len < k) {
    cout << 0 << endl;
  } else {
    long long sum = c(len - 1, k) * pow(9.00, k);
    int t = n[0] - '0' - 1;
    sum += (c(len - 1, k - 1) * pow(9.00, k - 1) * t);
    sum += 1;
    if (k >= 2) {
      t = n[1] - '0' - 1;
      sum += c(len - 2, k - 1) * pow(9.00, k - 1);
      sum += (c(len - 2, k - 2) * pow(9.00, k - 2) * t);
    }
    if (k == 3) {
      t = (n[2] - '0' - 1);
      sum += c(len - 3, k - 2) * pow(9.00, k - 2);
      sum += (c(len - 3, k - 3) * pow(9.00, k - 3) * t);
    }
    cout << sum << endl;
  }
  return 0;
}
