#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX;
const int MAX = 510000;
const long long MOD = 1000000007;
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 % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
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] % MOD) % MOD;
}
int main() {
  string n;
  long long k;
  cin >> n >> k;
  COMinit();
  long long ans = 0, m = n.size();
  if (k == 1) {
    ans = (m - 1) * 9 + n[0] - '0';
  }
  if (k == 2) {
    ans = 81 * COM(m - 1, 2);
    ans += (n[0] - '0' - 1) * (m - 1) * 9;
    ans += n[1] - '0';
    ans += (m - 2) * 9;
    if (m < 2) ans = 0;
  }
  if (k == 3) {
    ans += 729 * COM(m - 1, 3);
    ans += (n[0] - '0' - 1) * COM(m - 1, 2) * 81;
    ans += (n[1] - '0' - 1) * 9 * (m - 2) + (n[2] - '0') + (m - 3) * 9;
    ans += COM(m - 2, 2) * 81;
    if (m < 3) ans = 0;
  }
  cout << ans << endl;
}
