#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
int main() {
  string a;
  vector<int> V;
  cin >> a;
  for (int i = 0; i < a.length(); i++) {
    V.push_back((int)(a[i] - '0'));
  }
  int con;
  cin >> con;
  long long count = 0;
  long long ans;
  switch (con) {
    case 1:
      ans = (V.size() - 1) * 9;
      count = V[0];
      break;
    case 2:
      ans = (V.size() - 2) * (V.size() - 1) * 81 / 2;
      count = (V[0] - 1) * (V.size() - 1) * 9;
      count = count + V[1];
      count = count + (V.size() - 2) * 9;
      break;
    case 3:
      ans = (V.size() - 3) * (V.size() - 2) * (V.size() - 1) / 6 * 729;
      count = (V[0] - 1) * (V.size() - 1) * (V.size() - 2) / 2 * 81;
      count = count + (V.size() - 2) * (V.size() - 3) / 2 * 81;
      if (V[1] != 0) {
        count = count + (V[1] - 1) * (V.size() - 2) * 9;
        count = count + V[2] + (V.size() - 3) * 9;
      }
      break;
  }
  ans = ans + count;
  cout << ans << endl;
}
