#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
long long gcd(long long x, long long y) {
  long long tmp = 0;
  if (x < y) {
    tmp = x;
    x = y;
    y = tmp;
  }
  while (y > 0) {
    long long r = x % y;
    x = y;
    y = r;
  }
  return x;
}
long long lcm(long long x, long long y) { return x / gcd(x, y) * y; }
const int MAX = 1e6 + 1;
const long long MOD = 1e9 + 7;
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;
}
vector<long long> nCr;
long long kaijo(long long k) {
  long long sum = 1;
  for (long long i = 1; i <= k; ++i) {
    sum *= i;
    sum %= 1000000000 + 7;
  }
  return sum;
}
long long lmax(long long s, long long t) {
  if (s > t) {
    return s;
  } else {
    return t;
  }
}
long long lmin(long long s, long long t) {
  if (s < t) {
    return s;
  } else {
    return t;
  }
}
long long modpow(long long res, long long a, long long n, long long mod) {
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
vector<bool> IsPrime;
void sieve(size_t max) {
  if (max + 1 > IsPrime.size()) {
    IsPrime.resize(max + 1, true);
  }
  IsPrime[0] = false;
  IsPrime[1] = false;
  for (size_t i = 2; i * i <= max; ++i)
    if (IsPrime[i])
      for (size_t j = 2; i * j <= max; ++j) IsPrime[i * j] = false;
}
struct UnionFind {
  vector<int> par;
  UnionFind(int N) : par(N) {
    for (int i = 0; i < N; i++) par[i] = i;
  }
  int root(int x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) return;
    par[rx] = ry;
  }
  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};
int main() {
  string N;
  cin >> N;
  long long K;
  cin >> K;
  long long ans = 0;
  if (K == 1) {
    long long first = N[0] - '0' + 1;
    ans = first + 9 * (N.length() - 1);
    ans--;
  } else if (K == 2) {
    long long first = N[0] - '0';
    long long second = N[1] - '0';
    ans = (first - 1) * 9 + 1 * second + first * lmax((N.length() - 2), 0) * 9 +
          lmax((N.length() - 1), 0) * lmax((N.length() - 2), 0) * 9 * 9 / 2;
  } else if (K == 3) {
    long long first = N[0] - '0';
    long long second = N[1] - '0';
    long long third = N[2] - '0';
    ans = (first - 1) * 9 * 9;
    ans += 1 * lmax((second - 1), 0) * 9;
    ans += 1 * 1 * third;
    ans += first * 9 * 9 * lmax((N.length() - 3), 0) *
           lmax((N.length() - 4), 0) / 2;
    ans += first * 9 * 9 * lmax((N.length() - 3), 0) * 2;
    ans += 9 * 9 * 9 * lmax((N.length() - 1), 0) * lmax((N.length() - 2), 0) *
           lmax((N.length() - 3), 0) / 6;
  }
  cout << lmax(ans, 0) << endl;
  return 0;
}
