#include <bits/stdc++.h>
using namespace std;
using ll = long long;
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;
}
int main(void) {
  string n;
  cin >> n;
  ll k;
  cin >> k;
  ll nlen = n.length();
  ll ans = 0;
  for (ll i = 1; i <= nlen - 1; i++) {
    if (i < k) continue;
    if (k == 1)
      ans += 9;
    else if (k == 2) {
      ans += (i - 1) * 81;
    } else {
      ans += (i - 1) * (i - 2) * 729 / 2;
    }
  }
  if (k == 1) {
    ans += (n[0] - '0');
  } else if (k == 2) {
    int ret = 1;
    while (n[ret] == '0' && ret < nlen) {
      ++ret;
    }
    if (ret != nlen) {
      ans += (n[ret] - '0');
      ans += ((n[0] - '0') - 1) * 9;
      ans += (n[0] - '0') * (nlen - ret - 1) * 9;
    }
  } else {
    int reta, retb;
    reta = 1;
    retb = -1;
    while (n[reta] == '0' && reta < nlen) {
      ++reta;
    }
    if (reta != nlen) {
      retb = reta + 1;
      while (n[retb] == '0' && retb < nlen) {
        ++retb;
      }
    }
    if (reta != nlen) {
      if (retb != nlen) {
        ans += (n[retb] - '0');
        ans += 9 * (nlen - retb - 1);
        ans += ((n[reta] - '0') - 1) * 9 * (nlen - reta - 1);
        ans += (nlen - reta - 1) * (nlen - reta - 2) * 81 / 2;
      } else {
        ans += ((n[reta] - '0') - 1) * 9 * (nlen - reta - 1);
        ans += (nlen - reta - 1) * (nlen - reta - 2) * 81 / 2;
      }
      ans += (nlen - 1) * (nlen - 2) * (n[0] - '0' - 1) * 81 / 2;
    }
  }
  cout << ans << endl;
}
