#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long long mod = 998244353;
int inf = 1000001000;
long long INF = 1e18 + 5;
void Add(int &a, int b) {
  a += b;
  while (a >= MOD) a -= MOD;
  while (a < 0) a += MOD;
}
void Mul(int &a, int b) { a = 1LL * a * b % MOD; }
int Pow(int b, int e) {
  if (e < 0) e += MOD - 1;
  int ret = 1;
  while (e) {
    if (e & 1) ret = 1LL * ret * b % MOD;
    b = 1LL * b * b % MOD;
    e >>= 1;
  }
  return ret;
}
namespace Math {
const int NMAX = (int)1e7;
int pow2[1 + NMAX];
int fact[1 + NMAX], tcaf[1 + NMAX];
void Precalc() {
  fact[0] = pow2[0] = 1;
  for (int i = 1; i <= NMAX; ++i) {
    pow2[i] = pow2[i - 1];
    Add(pow2[i], pow2[i]);
    fact[i] = fact[i - 1];
    Mul(fact[i], i);
  }
  tcaf[NMAX] = Pow(fact[NMAX], -1);
  for (int i = NMAX - 1; i >= 0; --i) {
    tcaf[i] = tcaf[i + 1];
    Mul(tcaf[i], i + 1);
    assert(1LL * fact[i] * tcaf[i] % MOD == 1);
  }
}
int Choose(int n, int k) {
  if (k > n || n < 0) return 0;
  return 1LL * fact[n] * tcaf[n - k] % MOD * tcaf[k] % MOD;
}
};  // namespace Math
int main() {
  Math::Precalc();
  string s;
  int k;
  cin >> s >> k;
  if (k == 1) {
    int u = s[0] - '0';
    cout << (s.size() - 1) * 9 + u << endl;
  }
  if (k == 2) {
    long long u = 0;
    if (s.size() < 2) {
      cout << 0 << endl;
      return 0;
    }
    for (int(i) = 0; (i) < (s.size() - 1); (i)++) {
      long long p = 81;
      u += p * i;
    }
    long long v = 9, c = s[0] - '0';
    u += c * v * (s.size() - 1);
    long long cc = s[1] - '0';
    u += cc - 9;
    cout << u << endl;
  }
  if (k == 3) {
    long long u = 0;
    if (s.size() < 3) {
      cout << 0 << endl;
      return 0;
    }
    for (int(i) = 0; (i) < (s.size() - 1); (i)++) {
      long long p = 729;
      u += p * Math::Choose(i, 2);
    }
    long long v = 81, c = s[0] - '0';
    u += c * v * Math::Choose(s.size() - 1, 2);
    long long cc = s[1] - '0', vv = 9;
    u += (cc - 9) * vv * (s.size() - 2);
    long long ccc = s[2] - '0';
    u += ccc - 9;
    cout << u << endl;
  }
}
