#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T>
using ve = vector<T>;
template <typename T>
using pq2 = priority_queue<T>;
template <typename T>
using pq1 = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <typename T>
T lcm(T a, T b) {
  return a * b / gcd(a, b);
}
template <typename T>
T extgcd(T a, T b, T& x, T& y) {
  T d = a;
  if (b != 0) {
    d = extgcd(b, a % b, y, x);
    y -= (a / b) * x;
  } else
    x = 1, y = 0;
  return d;
}
template <typename T>
T modpow(T x, T n, T m) {
  if (n == 0) return 1;
  T resp = modpow(x * x % m, n / 2, m);
  if (n & 1) resp = resp * x % m;
  return resp;
}
template <typename T>
T modinverse(T a, T m) {
  T x, y;
  extgcd(a, m, x, y);
  return (m + x % m) % m;
}
struct combination {
  ll M = 1000000007;
  vector<ll> fact, ifact;
  combination(ll n) : fact(n + 1), ifact(n + 1) {
    fact[0] = 1;
    ifact[0] = 1;
    for (ll i = 0; i < n; i++) {
      fact[i + 1] = fact[i] * (i + 1) % M;
      ifact[i + 1] = ifact[i] * modpow(i + 1, M - 2, M) % M;
    }
  }
  ll com(ll a, ll b) {
    if (a == 0 && b == 0) return 1;
    if (a < b || a < 0) return 0;
    ll tmp = ifact[a - b] * ifact[b] % M;
    return tmp * fact[a] % M;
  }
};
int main() {
  string S;
  cin >> S;
  ll K;
  cin >> K;
  combination C(2000);
  ll ans = 0;
  ll n = S.length();
  if (K == 1)
    ans = (n - 1) * 9;
  else if (K == 2)
    ans = 9 * 9 * C.com(n - 1, 2);
  else
    ans = 9 * 9 * 9 * C.com(n - 1, 3);
  ll an = ll(S[0] - '0');
  if (K == 3) {
    ans += (an - 1) * 9 * 9 * C.com(n - 1, 2);
    bool f = false;
    for (int i = (1); i < (n); i++)
      for (int j = (i + 1); j < (n); j++) {
        if (S[i] == '0' && !f) continue;
        if (f) {
          ans += 81;
        } else {
          ans += ((ll)(S[i] - '0') - 1) * 9;
          ans += (ll)(S[i] - '0');
        }
        if (!f && S[i] != '0') f = true;
      }
  } else if (K == 2) {
    ans += (an - 1) * 9 * (n - 1);
    bool f = false;
    for (int i = (1); i < (n); i++) {
      if (f)
        ans += 9;
      else
        ans += ((ll)(S[i] - '0'));
      if (!f && S[i] != 0) f = true;
    }
  } else
    ans++;
  cout << ans << endl;
  return 0;
}
