#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const int INF = 1e9;
const lint LINF = 1e18;
const lint MOD = 1e9 + 7;
const double EPS = 1e-10;
const int mod = 1e18 + 7;
struct mint {
  long long x;
  mint(long long x = 0) : x((x % mod + mod) % mod) {}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};
struct combination {
  vector<mint> fact, ifact;
  combination(int n) : fact(n + 1), ifact(n + 1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
  mint operator()(int n) { return fact[n]; }
};
int main() {
  string N;
  int k;
  cin >> N >> k;
  combination comb(1000000);
  int D = N.size();
  if (k == 1) {
    lint ans = 0;
    for (int d = 1; d < D; d++) {
      ans += 9;
    }
    int M1 = N[0] - '0';
    for (int i = 1; i <= M1; i++) {
      ans += 1;
    }
    cout << ans << endl;
  } else if (k == 2) {
    lint ans = 0;
    if (D < 2) {
      cout << 0 << endl;
      return 0;
    }
    for (int d = 2; d < D; d++) {
      ans += 9 * 9 * comb(D - 1, 1).x;
    }
    int M1 = N[0] - '0';
    for (int x = 1; x < M1; x++) {
      ans += 9 * comb(D - 1, 1).x;
    }
    int idx = -1;
    for (int i = 2; i <= D; i++) {
      if (N[i - 1] != '0') {
        idx = i;
        break;
      }
    }
    if (idx == -1) {
      cout << ans << endl;
      return 0;
    } else {
      int M2 = N[idx - 1] - '0';
      for (int i = 1; i <= M2; i++) {
        ans += 1;
      }
      ans += 9 * comb(D - idx, 1).x;
    }
  } else {
    1;
  }
  return 0;
}
