#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MOD = 1000000007;
int first = 0;
vector<int> pp;
int len(string n) {
  int c = n.size();
  for (int i = 0; i < c; i++) {
    pp.push_back(n.at(i) - '0');
  }
  first = pp[0];
  return c;
}
int main() {
  int k;
  string n;
  cin >> n >> k;
  int c = len(n);
  vector<vector<vector<long long>>> dp(
      c, vector<vector<long long>>(4, vector<long long>(2, 0)));
  dp.at(0).at(0).at(0) = 0;
  dp.at(0).at(0).at(1) = 1;
  dp.at(0).at(1).at(0) = 1;
  dp.at(0).at(1).at(1) = first - 1;
  for (int i = 1; i < c; i++)
    for (int j = 0; j < 4; j++)
      for (int k = 0; k < 2; k++) {
        if (j == 0 && k == 1) {
          dp.at(i).at(j).at(k) = 1;
          continue;
        } else if (j == 0 && k == 0) {
          dp.at(i).at(j).at(k) = 0;
          continue;
        }
        if (k == 0) {
          if (pp.at(i) == 0) {
            dp.at(i).at(j).at(k) = dp.at(i - 1).at(j).at(k);
          } else {
            dp.at(i).at(j).at(k) = dp.at(i - 1).at(j - 1).at(k);
          }
        } else {
          dp.at(i).at(j).at(k) =
              dp.at(i - 1).at(j).at(k) + dp.at(i - 1).at(j - 1).at(k) * 9;
          if (pp.at(i - 1) != 0) {
            dp.at(i).at(j).at(k) +=
                dp.at(i - 1).at(j - 1).at(k - 1) * (pp.at(i) - 1) +
                dp.at(i - 1).at(j).at(k - 1);
          }
        }
      }
  long long ans = 0;
  if (k == 0)
    cout << ans << endl;
  else {
    for (int j = 0; j < 2; j++) {
      ans += dp.at(c - 1).at(k).at(j);
    }
    cout << ans << endl;
  }
  return 0;
}
