#include <bits/stdc++.h>
const int M = 2e5 + 10;
const int N = 1e5 + 10;
using namespace std;
inline long long read() {
  long long sum = 0, b = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') b = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    sum = sum * 10 + c - 48;
    c = getchar();
  }
  return b * sum;
}
long long n, m, b, k;
char s[110];
long long q_pow(long long x, long long y) {
  long long t = x, res = 1;
  while (y) {
    if (y & 1) res = res * t;
    t *= t;
    y >>= 1;
  }
  return res;
}
int main() {
  long long i, j;
  scanf("%s", s + 1);
  k = read();
  long long ans = 0;
  long long len = strlen(s + 1);
  if (k == 1) {
    long long x = s[1] - '0';
    ans = x + (len - 1) * 9;
  } else if (k == 2) {
    long long x = s[1] - 48, y = max(s[2] - 48, 0);
    ans = (x - 1) * 9 * (len - 1) + 81 * (len - 1) * (len - 2) / 2;
    ans++;
    ans += (y - 1) + 9 * (len - 2);
  } else if (k == 3) {
    long long x = s[1] - 48;
    long long y = max(s[2] - 48, 0), z = max(s[3] - 48, 0);
    ans = (x - 1) * 81 * (len - 2) * (len - 1) / 2 +
          81 * 9 * (len - 1) * (len - 2) * (len - 3) / 6;
    ans++;
    ans += 81 * (len - 3) * (len - 4) / 2 + (y - 2) * 9 * (len - 2) +
           (z - 1) * (len - 3) * 9;
  }
  printf("%lld", ans);
  return 0;
}
