#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = 1LL << 60;
constexpr int inf = 1e9;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
};
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
};
template <typename T>
inline string toString(const T& a) {
  ostringstream oss;
  oss << a;
  return oss.str();
};
int main() {
  string S;
  cin >> S;
  ll K;
  cin >> K;
  ll N;
  N = S.size();
  ll ans = 0;
  if (N == 1) {
    if (K == 1) {
      cout << S[0] - '0' << endl;
    } else {
      cout << 0 << endl;
    }
    return 0;
  }
  if (N < K) {
    cout << 0 << endl;
    return 0;
  }
  ll s = S[0] - '0';
  if (K == 1) {
    ans += 9LL * (N - 1);
    ans += S[0] - '0';
  } else if (K == 2) {
    ll temp = 1;
    if (N >= 3) {
      for (int i = 0; i < K; i++) {
        temp *= N - 1 - i;
      }
      for (int i = 1; i <= K; i++) {
        temp /= i;
      }
      for (int i = 0; i < K; i++) {
        temp *= 9LL;
      }
      ans += temp;
    }
    ans += (s - 1LL) * (N - 1LL) * 9LL;
    for (int i = 1; i < K - 1; i++) {
      ans += S[i] - '0';
    }
    ans += 9LL * max(0LL, N - 2);
    ans += S[1] - '0';
  } else {
    ll temp = 1;
    for (int i = 0; i < K; i++) {
      temp *= N - 1 - i;
    }
    for (int i = 1; i <= K; i++) {
      temp /= i;
    }
    for (int i = 0; i < K; i++) {
      temp *= 9LL;
    }
    ans += temp;
    temp = 1;
    for (int i = 0; i < 2; i++) {
      temp *= N - 1 - i;
    }
    for (int i = 1; i <= 2; i++) {
      temp /= i;
    }
    for (int i = 0; i < 2; i++) {
      temp *= 9LL;
    }
    temp *= s - 1;
    ans += temp;
    temp = 1;
    for (int i = 0; i < 2; i++) {
      temp *= N - 2 - i;
    }
    for (int i = 1; i <= 2; i++) {
      temp /= i;
    }
    for (int i = 0; i < 2; i++) {
      temp *= 9LL;
    }
    ans += temp;
    ans += (ll)(S[1] - '0' - 1) * (max(0LL, N - 2LL)) * 9LL;
    ans += (max(0LL, N - 2LL)) * 9LL;
  }
  cout << ans << endl;
  return 0;
}
