#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = 2000000015;
const long long MAX = 510000;
const long long MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
long long jousu(long long x00, long long y00) {
  long long z00 = 1;
  for (long long i = 0; i < y00; i++) {
    z00 *= x00;
  }
  return z00;
}
long long keta(long long x00) {
  long long z00 = x00;
  long long w00 = 0;
  while (z00 != 0) {
    z00 /= 10;
    w00++;
  }
  return w00;
}
long long krag(double xx) { return INF - (long long)(INF - xx); }
long long b_s(vector<long long>& vecxx, long long xx) {
  if (xx <= vecxx[0]) {
    return 0;
  }
  if (vecxx.back() < xx) {
    return vecxx.size();
  }
  long long aa1 = 0, aa2 = vecxx.size() - 1, aa3;
  while (aa1 + 1 < aa2) {
    aa3 = (aa1 + aa2) / 2;
    if (vecxx[aa3] >= xx) {
      aa2 = aa3;
    } else {
      aa1 = aa3;
    }
  }
  return aa2;
}
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (long long 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(long long n, long long k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
long long modpow(long long a, long long n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
long long gcd(long long xx, long long yy) {
  long long p = xx;
  long long q = yy;
  if (q > p) swap(p, q);
  while (p % q != 0) {
    p %= q;
    swap(p, q);
  }
  return q;
}
long long lcm(long long xx, long long yy) { return xx * yy / gcd(xx, yy); }
bool prime(long long xx) {
  long long a = xx;
  for (long long i = 2; i * i <= xx; i++) {
    if (xx % i == 0) {
      return 0;
    }
  }
  return 1;
}
signed main() {
  string n;
  long long k, ans = 0;
  cin >> n >> k;
  if (k == 1) {
    cout << (n.size() - 1) * 9 + (n[0] - '0') << "\n";
  }
  if (k == 2) {
    ans += (long long)(n.size() - 1) * (n.size() - 2) / 2 * 81;
    ans += ((long long)(n[0] - '0') - 1) * (n.size() - 1) * 9;
    long long i = 1;
    while (i < n.size() && n[i] == '0') {
      i++;
    }
    ans += max(0ll, (long long)n.size() - i - 1ll) * 9;
    if (i != n.size()) {
      ans += (long long)n[i] - '0';
    }
    cout << i << "\n";
    cout << ans << "\n";
  }
  if (k == 3) {
    if (n.size() < 3) {
      cout << 0 << "\n";
      return 0;
    }
    ans +=
        (long long)(n.size() - 3) * (n.size() - 2) * (n.size() - 1) / 6 * 729;
    ans +=
        ((long long)n[0] - '0' - 1) * (n.size() - 1) * (n.size() - 2) / 2 * 81;
    long long i = 1;
    while (i < n.size() && n[i] == '0') {
      i++;
    }
    ans += max((long long unsigned)0, (long long unsigned)(n.size() - i - 1) *
                                          (n.size() - i - 2) / 2ll * 81);
    ans += max(0ll, (long long)n[i] - '0' - 1) * (n.size() - i - 1) * 9;
    if (i < n.size() - 1) {
      ans += (long long)n[i + 1] - '0';
      ans += max(0ll, (long long)(n.size() - 2ll - i)) * 9;
    }
    cout << ans << "\n";
  }
}
