#include <bits/stdc++.h>
using namespace std;
struct aaa {
  aaa() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  };
} aaa;
template <class T>
ostream &operator<<(ostream &o, const vector<T> &v) {
  o << "{";
  for (int i = 0; i < (int)v.size(); i++) o << (i > 0 ? ", " : "") << v[i];
  o << "}";
  return o;
}
using int64 = long long;
int main() {
  string s;
  int k;
  cin >> s >> k;
  vector<int> n;
  for (auto a : s) n.push_back(a - '0');
  int l = n.size();
  vector<vector<vector<int>>> dp(100,
                                 vector<vector<int>>(2, vector<int>(4, 0)));
  dp[0][0][0] = 1;
  for (int i = 0; i < l; i++) {
    for (int smaller = 0; smaller < 2; smaller++) {
      for (int j = 0; j <= 2; j++) {
        for (int x = 0; x <= (smaller ? 9 : n[i]); x++) {
          dp[i + 1][smaller || x < n[i]][j + (x != 0 ? 1 : 0)] +=
              dp[i][smaller][j];
        }
      }
    }
  }
  cout << dp[l][0][k] + dp[l][1][k] << endl;
}
