#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
int ctoi(char c) { return int(c - '0'); }
int calc1(const char s[100], int i, int n) {
  return ctoi(s[i]) + 9 * (n - i - 1);
}
int calc2(const char s[100], int i, int n) {
  int sum = 0;
  if (i + 1 < n) {
    sum += (ctoi(s[i]) - 1) * 9 * (n - i - 1);
    sum += ctoi(s[i + 1]);
  }
  if (i + 2 < n) {
    sum += 9 * (n - i - 2);
    sum += 9 * 9 * (n - 1 - i) * (n - 2 - i) / 2;
  }
  return sum;
}
int calc3(const char s[100], int i, int n) {
  int sum = 0;
  if (i + 2 < n) {
    sum += (ctoi(s[i]) - 1) * 9 * 9 * (n - 1 - i) * (n - 2 - i) / 2;
    for (int j = i + 1; j < (int)(n - 1); ++j) {
      sum += ctoi(s[j]) * ctoi(s[j + 1]);
    }
  }
  if (i + 3 < n) {
    for (int j = i + 1; j < (int)(n - 1); ++j) {
      sum += ctoi(s[j]) * 9 * (n - j - 2);
    }
    sum += 9 * 9 * 9 * (n - 1 - i) * (n - 2 - i) * (n - 3 - i) / 6;
  }
  return sum;
}
int main() {
  char s[100];
  int k;
  scanf("%s", s);
  scanf("%d", &k);
  int n = 0;
  while (s[n] != '\0') {
    ++n;
  }
  ll sum = 0;
  if (k == 1) {
    sum += calc1(s, 0, n);
    cout << sum << endl;
    return 0;
  }
  if (k == 2) {
    sum += calc2(s, 0, n);
    cout << sum << endl;
    return 0;
  }
  if (k == 3) {
    sum += calc3(s, 0, n);
    cout << sum << endl;
    return 0;
  }
  return 0;
}
