#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
long long GCD(long long a, long long b) { return b ? GCD(b, a % b) : a; }
long long LCM(long long a, long long b) { return a / GCD(a, b) * b; }
int dx[8] = {-1, 0, 1, 0, 1, 1, -1, -1};
int dy[8] = {0, -1, 0, 1, 1, -1, 1, -1};
char dir[4] = {'u', 'l', 'd', 'r'};
long long int cmp1(pair<long long int, string> a,
                   pair<long long int, string> b) {
  if (a.first != b.first)
    return a.first < b.first;
  else
    return a.second < b.second;
}
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % 1000000007;
    inv[i] = 1000000007 - inv[1000000007 % i] * (1000000007 / i) % 1000000007;
    finv[i] = finv[i - 1] * inv[i] % 1000000007;
  }
}
long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % 1000000007) % 1000000007;
}
long long modpow(long long a, long long n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % 1000000007;
    a = a * a % 1000000007;
    n >>= 1;
  }
  return res;
}
long long int waru(long long int a, long long int b) {
  return a * modpow(b, 1000000007 - 2) % 1000000007;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  COMinit();
  string n;
  cin >> n;
  long long int k;
  cin >> k;
  long long int ans = 0;
  long long int l = n.length();
  for (int i = 0; i < l; i++) {
    if (k == 1) {
      long long int tmp = (0 > n[i] - '0' ? 0 : n[i] - '0');
      ans += tmp * (9 * (l - 1 - i));
    } else if (k == 2) {
      long long int tmp = (0 > n[i] - '0' - 1 ? 0 : n[i] - '0' - 1);
      if (i == 0) {
        ans += 81 * COM((l - 1 - i), 2);
        ans += tmp * (COM(l - 1 - i, 1) * 9);
      } else {
        if (i == 1) {
          ans += (COM(l - i - 1, 1) * 9);
          ans += tmp + 1;
        }
      }
    } else if (k == 3) {
      long long int tmp = (0 > n[i] - '0' - 1 ? 0 : n[i] - '0' - 1);
      if (i == 0) {
        ans += 81 * 9 * COM((l - 1 - i), 3);
        ans += tmp * (COM(l - 1 - i, 2) * 81);
      } else {
        if (i == 1) {
          ans += 81 * (COM(l - i - 1, 2));
          ans += tmp * (COM(l - i - 1, 1) * 9);
        }
        if (i == 2) {
          ans += (COM(l - i - 1, 1) * 9);
          ans += tmp + 1;
        }
      }
    }
  }
  if (k == 1) {
    ans += n[0] - '0';
  }
  cout << ans << endl;
  return 0;
}
