#include <bits/stdc++.h>
using namespace std;
const long long INF = (1 << 30) - 1;
const long long LLINF = (1LL << 60LL);
const long long MOD = 1000000007;
const long long mod = 998244353;
const long long MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
long long dx[8] = {1, 0, -1, 0, 1, -1, 1, -1};
long long dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
void solve() {
  string s;
  long long k;
  cin >> s >> k;
  long long n = s.size();
  long long ans = 0;
  for (long long i = 1; i < n; i++) {
    if (k == 1) {
      ans += 9;
    } else if (k == 2) {
      if (i == 1) continue;
      ans += 9 * (i - 1) * 9;
    } else if (k == 3) {
      if (i < k) continue;
      ans += 9 * (i - 1) * (i - 2) / 2 * 9 * 9;
    }
  }
  long long a = s[0] - '0';
  if (k == 1)
    ans += a;
  else if (k == 2) {
    ans += (a - 1) * (n - 1) * 9;
    bool ok = false;
    for (long long i = 1; i < n; i++) {
      if (s[i] == '0' && ok == false) continue;
      if (ok)
        ans += 9;
      else {
        if (s[i] != '0') ok = true;
        long long b = s[i] - '0';
        ans += b;
      }
    }
  } else if (k == 3) {
    ans += (a - 1) * (n - 1) * (n - 2) / 2 * 9 * 9;
    bool ok = false;
    long long sum = 0;
    for (long long i = 1; i < n; i++) {
      if (s[i] == '0' && ok == false) continue;
      if (sum == 1 && s[i] != '0') {
        ans += (s[i] - '0');
      }
      if (ok) {
        ans += (n - i - 1) * 9 * 9;
      } else {
        if (s[i] != '0') ok = true;
        long long b = s[i] - '0';
        ans += (b - 1) * (n - i - 1) * 9;
        sum = 1;
      }
    }
  }
  cout << ans << endl;
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  solve();
  return 0;
}
