#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fLL;
const int mod = 1e9 + 7;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int pct(int x) { return __builtin_popcount(x); }
int bit(int x) { return 31 - __builtin_clz(x); }
int cdiv(int a, int b) { return a / b + !(a < 0 || a % b == 0); }
void DBG() { cerr << "]" << endl; }
template <class H, class... T>
void DBG(H h, T... t) {
  cerr << to_string(h);
  if (sizeof...(t)) cerr << ", ";
  DBG(t...);
}
const int maxn = 1e5 * 3 + 20;
int n, _, q, k;
int nz[1000];
int choose(int c, int e) {
  if (e == 0)
    return 1;
  else {
    int fr = c - e + 1;
    int r = 1;
    for (signed i = fr; i <= c; i++) {
      r *= i;
    }
    int d = 1;
    for (signed i = 1; i <= e; i++) d *= i;
    r /= d;
    return r;
  }
}
void solve() {
  string s;
  cin >> s >> k;
  reverse(begin(s), end(s));
  int cnt = 0;
  nz[0] = 0;
  for (signed i = 1; i <= (signed)s.size(); i++) {
    nz[i] = nz[i - 1] + (s[i - 1] != '0');
  }
  for (signed i = (signed)s.size() - 1; i >= 0; i--) {
    int p = s[i] - '0';
    42;
    if (p && k - 1 >= 0) {
      int res1 = 0;
      if (k - 1 <= i) {
        if (i == 0) {
          res1 = ((p)*choose(i, k - 1) * pow(9, k - 1));
        } else {
          res1 = ((p - 1) * choose(i, k - 1) * pow(9, k - 1));
        }
      }
      42;
      cnt += res1;
    }
    if (k >= 0) {
      if (i >= k) {
        int res2 = (choose(i, k) * powl(9, k));
        42;
        cnt += res2;
        k--;
        continue;
      }
    }
    if (p > 0) k--;
  }
  cout << cnt << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return 0;
}
