#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
const ll MOD = 1000000007;
const ll MOD9 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 4e18;
const ll dy[8] = {1, 0, -1, 0, 1, 1, -1, -1};
const ll dx[8] = {0, -1, 0, 1, 1, -1, 1, -1};
using Graph = vector<vector<int>>;
double nCk(int n, int k) {
  double res = 1.0;
  for (int i = 0; i < n; i++) {
    res *= 0.5;
  }
  for (int i = 0; i < k; i++) {
    res *= (double)(n - i);
    res /= (double)(k - i);
  }
  return res;
}
struct edge {
  ll to, cost;
};
struct graph {
  ll V;
  vector<vector<edge>> G;
  vector<ll> d;
  graph(ll n) { init(n); }
  void init(ll n) {
    V = n;
    G.resize(V);
    d.resize(V);
    for (ll i = 0; i < V; i++) {
      d[i] = INF;
    }
  }
  void add_edge(ll s, ll t, ll cost) {
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
  }
  void dijkstra(ll s) {
    for (ll i = 0; i < V; i++) {
      d[i] = INF;
    }
    d[s] = 0;
    priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>
        que;
    que.push(pair<ll, ll>(0, s));
    while (!que.empty()) {
      pair<ll, ll> p = que.top();
      que.pop();
      ll v = p.second;
      if (d[v] < p.first) continue;
      for (auto e : G[v]) {
        if (d[e.to] > d[v] + e.cost) {
          d[e.to] = d[v] + e.cost;
          que.push(pair<ll, ll>(d[e.to], e.to));
        }
      }
    }
  }
};
class UnionFind {
 public:
  int par[100005];
  int depth[100005];
  int nGroup[100005];
  UnionFind(int n) { init(n); }
  void init(int n) {
    for (int i = 0; i < n; i++) {
      par[i] = i;
      depth[i] = 0;
      nGroup[i] = 1;
    }
  }
  int root(int x) {
    if (par[x] == x) {
      return x;
    } else {
      return par[x] = root(par[x]);
    }
  }
  bool same(int x, int y) { return root(x) == root(y); }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return;
    if (depth[x] < depth[y]) {
      par[x] = y;
      nGroup[y] += nGroup[x];
      nGroup[x] = 0;
    } else {
      par[y] = x;
      nGroup[x] += nGroup[y];
      nGroup[y] = 0;
      if (depth[x] == depth[y]) depth[x]++;
    }
  }
};
const ll MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int 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;
  }
}
ll COM(ll n, ll k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
  string s;
  cin >> s;
  ll K;
  cin >> K;
  ll n = s.size();
  ll dp[100][10][10] = {};
  dp[0][0][0] = 1;
  for (ll i = 0; i < n; i++) {
    ll p = s.at(i) - '0';
    for (ll j = 0; j < 2; j++) {
      for (ll k = 0; k <= K; k++) {
        for (ll h = 0; h <= (j ? 9 : p); h++) {
          if (h == 0) {
            dp[i + 1][j || (h < p)][k] += dp[i][j][k];
          } else {
            dp[i + 1][j || (h < p)][k + 1] += dp[i][j][k];
          }
        }
      }
    }
  }
  ll ans = dp[n][0][K] + dp[n][1][K];
  cout << ans << endl;
}
