#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:33554432")
using namespace std;
void dout() { cerr << endl; }
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
  cerr << H << ' ';
  dout(T...);
}
using ll = long long;
using ld = long double;
void precalc() {}
ll getnCr(ll n, ll k) {
  if (k < 0) return 0;
  if (k == 0) return 1;
  ll ret = 1;
  for (int i = 0; i < k; ++i) ret *= n - i;
  for (int i = 1; i <= k; ++i) ret /= i;
  return ret;
}
void solve() {
  string s;
  cin >> s;
  ll k;
  cin >> k;
  ll answr = 0;
  ll len = s.size();
  map<int, int> tnpow;
  tnpow[0] = 1;
  tnpow[1] = 9;
  tnpow[2] = 81;
  tnpow[3] = 81 * 9;
  if (len >= k) {
    ll dig = s[0] - '0';
    dig -= 1;
    answr += getnCr(len - 1, k) * tnpow[k] +
             dig * getnCr(len - 1, k - 1) * tnpow[k - 1];
    if (k == 1) answr++;
  }
  if (k > 1) {
    ll dig = s[1] - '0';
    dig -= 1;
    answr += getnCr(len - 2, k - 1) * tnpow[k - 1] +
             dig * getnCr(len - 2, k - 2) * tnpow[k - 2];
    if (k == 2) answr++;
  }
  if (k > 2) {
    answr += max(0ll, len - 2) * 9;
  }
  cout << answr;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(20);
  precalc();
  solve();
}
