#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  char ch = getchar();
  long long nega = 1;
  while (!isdigit(ch)) {
    if (ch == '-') nega = -1;
    ch = getchar();
  }
  long long ans = 0;
  while (isdigit(ch)) {
    ans = ans * 10 + ch - 48;
    ch = getchar();
  }
  if (nega == -1) return -ans;
  return ans;
}
long long add(long long x, long long y) {
  return x + y >= 998244353 ? x + y - 998244353 : x + y;
}
long long sub(long long x, long long y) {
  return x - y < 0 ? x - y + 998244353 : x - y;
}
long long mul(long long x, long long y) { return 1LL * x * y % 998244353; }
long long a[105];
long long sol(long long x, long long n) {
  if (x == n) return 0;
  long long ans = 0;
  for (long long i = x + 1; i < n; i++) ans += 9 * (n - i) * 9;
  ans += (a[x] - 1) * 9 * (n - x);
  long long cur = x + 1;
  while (cur <= n && a[cur] == 0) cur++;
  if (cur != n + 1) {
    ans += (n - cur) * 9;
    ans += a[cur];
  }
  return ans;
}
signed main() {
  string s;
  cin >> s;
  long long n = s.length();
  for (long long i = 1; i <= n; i++) a[i] = s[i - 1] - '0';
  long long k = read();
  if (k == 1) {
    long long ans = 9 * (n - 1);
    ans += a[1];
    cout << ans << endl;
  }
  if (k == 2) {
    long long ans = 0;
    if (n == 1) {
      cout << "0\n";
      return 0;
    }
    for (long long i = 2; i < n; i++) ans += 9 * (i - 1) * 9;
    ans += (a[1] - 1) * 9 * (n - 1);
    long long cur = 2;
    while (cur <= n && a[cur] == 0) cur++;
    if (cur != n + 1) {
      ans += (n - cur) * 9;
      ans += a[cur];
    }
    cout << ans << endl;
  }
  if (k == 3) {
    if (n <= 2) {
      cout << "0\n";
      return 0;
    }
    long long ans = 0;
    for (long long i = 3; i < n; i++) ans += 9 * 9 * 9 * (i - 1) * (i - 2) / 2;
    ans += (a[1] - 1) * 9 * 9 * (n - 1) * (n - 2) / 2;
    long long cur = 2;
    if (cur != n + 1) {
      ans += sol(cur, n);
    }
    cout << ans << endl;
  }
  return 0;
}
