#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
const long long mod = 1000000007;
const long long dx[4] = {1, 0, -1, 0};
const long long dy[4] = {0, -1, 0, 1};
long long ketawa(long long n) {
  long long a = 0;
  while (n != 0) {
    a += n % 10;
    n /= 10;
  }
  return a;
}
long long RepeatSquaring(long long N, long long pair<long long, long long>,
                         long long M) {
  if (pair<long long, long long> == 0) return 1;
  if (pair<long long, long long> % 2 == 0) {
    long long t = RepeatSquaring(N, pair<long long, long long> / 2, M);
    return (t % M) * (t % M) % M;
  }
  return (N * RepeatSquaring(N, pair<long long, long long> - 1, M)) % M;
}
bool IsPrime(long long a) {
  if (a == 1) return false;
  for (int i = 2; i * i <= a; i++) {
    if (a % i == 0 && a != i) {
      return false;
    }
  }
  return true;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long extgcd(long long a, long long b, long long& x, long long& y) {
  if (b == 0) {
    x = 1, y = 0;
    return a;
  }
  long long q = a / b, g = extgcd(b, a - q * b, x, y);
  long long z = x - q * y;
  x = y;
  y = z;
  return g;
}
long long invmod(long long a, long long m) {
  long long x, y;
  extgcd(a, m, x, y);
  x %= m;
  if (x < 0) x += m;
  return x;
}
long long nCk(long long n, long long k, long long mod) {
  long long ans = 1;
  for (long long i = n, j = 1; j <= k; i--, j++)
    ans = (((ans * i) % mod) * invmod(j, mod)) % mod;
  return ans;
}
long long lmin(long long a, long long b) { return a > b ? b : a; };
long long lmax(long long a, long long b) { return a > b ? a : b; };
long long lsum(long long a, long long b) { return a + b; };
template <typename T>
class Zip {
  vector<T> d;
  bool flag;

 public:
  Zip() { flag = false; }
  void add(T x) {
    d.push_back(x);
    flag = true;
  }
  long long getNum(T x) {
    if (flag) {
      sort(d.begin(), d.end());
      d.erase(unique(d.begin(), d.end()), d.end());
      flag = false;
    }
    return lower_bound(d.begin(), d.end(), x) - d.begin();
  }
  long long size() {
    if (flag) {
      sort(d.begin(), d.end());
      d.erase(unique(d.begin(), d.end()), d.end());
      flag = false;
    }
    return (long long)d.size();
  }
};
class UnionFind {
  vector<long long> par, rank;

 public:
  void init(long long n) {
    par.resize(n, 1);
    rank.resize(n, 0);
  }
  long long getSize(long long x) { return par[find(x)]; }
  long long find(long long x) {
    if (par[x] > 0) return x;
    return -(par[x] = -find(-par[x]));
  }
  void merge(long long x, long long y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (rank[x] < rank[y]) {
      par[y] += par[x];
      par[x] = -y;
    } else {
      par[x] += par[y];
      par[y] = -x;
      if (rank[x] == rank[y]) rank[x]++;
    }
  }
  bool isSame(long long x, long long y) { return find(x) == find(y); }
};
class SegmentTree {
 public:
  vector<pair<double, double>> node;
  long long n;
  pair<double, double> initial_value;

 public:
  void Init(long long n_, pair<double, double> initial_value_) {
    n = 1;
    while (n < n_) n *= 2;
    node.resize(2 * n);
    for (long long i = 0; i < 2 * n; i++) {
      node[i] = initial_value_;
    }
    initial_value = initial_value_;
  }
  void Update(long long k, pair<double, double> a) {
    k += n;
    node[k] = a;
    while (k > 1) {
      k = k / 2;
      node[k] = pair<double, double>(
          node[k * 2].first * node[k * 2 + 1].first,
          node[k * 2].second * node[k * 2 + 1].first + node[k * 2 + 1].second);
    }
  }
  double Query() { return node[1].first + node[1].second; }
};
long long lis(long long* a, long long n, long long* dp) {
  fill(dp, dp + n, INF);
  for (long long i = 0; i < n; i++) *lower_bound(dp, dp + n, a[i]) = a[i];
  return (long long)(lower_bound(dp, dp + n, INF) - dp);
}
string n;
long long k;
long long dp[101][4];
long long dpa[101][4][2];
long long ans;
int main() {
  cin >> n >> k;
  dp[1][1] = 9;
  for (long long i = 2; i <= 100; i++) {
    dp[i][1] += dp[i - 1][1];
    dp[i][2] += dp[i - 1][2];
    dp[i][3] += dp[i - 1][3];
    dp[i][2] += dp[i - 1][1] * 9;
    dp[i][3] += dp[i - 1][2] * 9;
  }
  for (long long i = 1; i < n.size(); i++) {
    ans += dp[i][k];
  }
  dpa[0][1][0] = 1;
  dpa[0][1][1] = (n[0] - '0') - 1;
  for (long long i = 1; i < n.size(); i++) {
    long long ima = (n[i] - '0');
    if (ima == 0) {
      dpa[i][1][0] += dpa[i - 1][1][0];
      dpa[i][2][0] += dpa[i - 1][2][0];
      dpa[i][3][0] += dpa[i - 1][3][0];
    } else {
      dpa[i][2][0] += dpa[i - 1][1][0];
      dpa[i][3][0] += dpa[i - 1][2][0];
      dpa[i][2][1] += dpa[i - 1][1][0] * (ima - 1);
      dpa[i][1][1] += dpa[i - 1][1][0];
      dpa[i][3][1] += dpa[i - 1][2][0] * (ima - 1);
      dpa[i][2][1] += dpa[i - 1][2][0];
    }
    dpa[i][2][1] += dpa[i - 1][1][1] * 9;
    dpa[i][3][1] += dpa[i - 1][2][1] * 9;
    dpa[i][1][1] += dpa[i - 1][1][1];
    dpa[i][2][1] += dpa[i - 1][2][1];
    dpa[i][3][1] += dpa[i - 1][3][1];
  }
  if (n[n.size()] == 9) ans++;
  cout << ans + dpa[n.size() - 1][k][0] + dpa[n.size() - 1][k][1] << endl;
}
