#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using vvs = vector<vs>;
using vc = vector<char>;
using vvc = vector<vc>;
using vb = vector<bool>;
using vvb = vector<vb>;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
const long long INF = 1LL << 60;
bool is_int_lround(double x) { return std::lround(x) == x; }
ll keta(ll x) {
  ll n = 0;
  while (x > 0) {
    x /= 10;
    n++;
  }
  return n;
}
ll conbi(int n, int m) {
  cin >> n >> m;
  vector<ll> a(100);
  a[0] = 1;
  for (int i = 0; i < 14; i++) {
    a[i + 1] = a[i] * (i + 1);
  }
  return a[n] / (a[m] * a[n - m]);
}
long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
ll kaijo(ll x) {
  ll z = 1;
  if (x == 0) {
    return 1;
  }
  while (x > 0) {
    z *= x;
    z %= 1000000007;
    x--;
  }
  return z;
}
ll yakusu_num(ll n) {
  vl yakusu(n + 1, 1);
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      n /= i;
      yakusu[i]++;
    }
  }
  if (n != 1) yakusu[n]++;
  ll num = 1;
  for (ll i = 0; i <= n; i++) {
    num *= yakusu[i];
  }
  return num;
}
int main() {
  string N;
  cin >> N;
  ll K;
  cin >> K;
  ll ans = 0;
  if (K == 1) {
    ans = (N[0] - '0') + 9 * (N.size() - 1);
    cout << ans << endl;
  } else if (K == 2) {
    if (N.size() >= 2) {
      ll bi = N.size();
      ans += (N[1] - '0');
      ans += (N.size() - 2) * 9;
      ans += (N[0] - '0' - 1) * (N.size() - 1) * 9;
      bi--;
      while (bi != 0) {
        ans += 9 * (bi - 1) * 9;
        bi--;
      }
    }
    cout << ans << endl;
  } else {
    ll bi = N.size();
    if (bi >= 3) {
      ll in = 0;
      for (ll i = 1; i < bi; i++) {
        if (N[i] != '0') {
          in = i;
          break;
        }
      }
      bool ok = false;
      for (ll i = in + 1; i < bi; i++) {
        if (N[i] != '0' && (ok == false)) {
          ans += (N[i] - '0');
          ok = true;
        } else if (ok) {
          ans += 9;
        }
      }
      ans += ((N[in] - '0') - 1) * (bi - in - 1) * 9;
      ans += ((N[0] - '0') - 1) * 9 * 9 * (bi - 1) * (bi - 2) / 2;
      ans += 9 * 9 * (bi - in - 1) * (bi - in - 2) / 2;
      bi -= 2;
      while (bi != 0) {
        ans += 9 * 9 * 9 * bi * (bi - 1) / 2;
        bi--;
      }
    }
    cout << ans << endl;
  }
}
