#include <bits/stdc++.h>
using namespace std;
string s;
long long k, len, ans, sum;
inline long long read() {
  long long x = 0;
  long long flag = 0;
  char ch;
  ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') flag = 1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + ch - 48;
    ch = getchar();
  }
  if (flag == 1) x = -x;
  return x;
}
inline long long C(int m) { return m * (m - 1) / 2; }
int main() {
  cin >> s;
  k = read();
  len = s.length();
  if (k == 1) {
    for (register int i = 1; i < len; i++) {
      ans += 9;
    }
    ans += s[0] - 48;
    printf("%lld\n", ans);
    return 0;
  }
  if (k == 2) {
    for (register int i = 1; i <= len - k; i++) {
      ans += 81 * i;
    }
    ans += s[1] - 48 + (s[0] - 48) * (len - 2) * 9 + (s[0] - 49) * 9;
    printf("%lld\n", ans);
    return 0;
  }
  if (k == 3) {
    for (register int i = 1; i <= len - k; i++) {
      ans += 729 * C(i - 1);
    }
    if (s[1] - 48 > 0) ans += s[2] - 48;
    if (s[1] - 49 > 0) ans += (s[1] - 49) * (len - 2) * 9;
    if (s[0] - 49 > 0) ans += (s[0] - 49) * 81 * C(len - 1);
    printf("%lld\n", ans);
  }
  return 0;
}
