#include <bits/stdc++.h>
using namespace std;
struct Init {
  Init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.precision(20);
    cout << fixed;
  }
} init;
template <typename _Ty>
ostream& operator<<(ostream& ostr, const vector<_Ty>& v) {
  for (int i = 0; i < (int)v.size(); i++) {
    ostr << v[i] << (i + 1 != v.size() ? " " : "");
  }
  return ostr;
}
template <typename _K, typename _V>
ostream& operator<<(ostream& ostr, const map<_K, _V>& v) {
  ostr << "{";
  for (auto iter = v.begin(); iter != v.end(); ++iter) {
    ostr << (*iter).first << ": " << (*iter).second << ", ";
  }
  ostr << "}";
  return ostr;
}
template <typename _K>
ostream& operator<<(ostream& ostr, const set<_K>& v) {
  for (auto iter = v.begin(); iter != v.end(); ++iter) {
    ostr << *iter << (iter != v.end() ? " " : "");
  }
  return ostr;
}
template <typename _K, typename _V>
ostream& operator<<(ostream& ostr, const pair<_K, _V>& v) {
  ostr << v.first << " " << v.second;
  return ostr;
}
int nCr(int n, int r) {
  int result = 1;
  for (int i = 0; i < r; i++) {
    result *= (n - i);
  }
  for (int i = 0; i < r; i++) {
    result = result / (i + 1);
  }
  return result;
}
int main() {
  string S;
  cin >> S;
  int K;
  cin >> K;
  if (S.size() < 7) {
    int N = atoi(S.c_str());
    int ans = 0;
    for (int i = 1; i < N + 1; i++) {
      string s = to_string(i);
      int p = 0;
      for (int j = 0; j < s.size(); j++) {
        if (s[j] != '0') p++;
      }
      if (p == K) ans++;
    }
    cout << ans << endl;
    exit(0);
  }
  int t = S.size() - 1;
  int p = 1;
  for (int i = 0; i < K; i++) p *= 9;
  int ans = nCr(t, K) * p;
  int head = S[0] - '0';
  int second = S[1] - '0';
  int a2 = nCr(t, K - 1) * (p / 9);
  int a3 = nCr(t - 1, K - 1) * (p / 9);
  int a4 = nCr(t - 1, K - 2);
  for (int i = 1; i < head + 1; i++) {
    if (i == head) {
      for (int j = 0; j < second + 1; j++) {
        if (j == second) {
          if (K - 2 == 0) {
            ans += 1;
          } else if (K - 2 == 1) {
            for (int k = 2; k < S.size(); k++) {
              int pp = S[k] - '0';
              ans += pp;
              if (k > 2) {
                ans += 9 - pp;
              }
            }
          }
        } else if (j == 0) {
          ans += a3;
        } else {
          ans += a4 * (p / 81);
        }
      }
    } else {
      ans += a2;
    }
  }
  cout << ans << endl;
}
