#include <bits/stdc++.h>
using namespace std;
using ul = unsigned long;
using ll = long long;
using ld = long double;
using vint = vector<int>;
using vll = vector<ll>;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using vpint = vector<pint>;
using vpll = vector<pll>;
const int INF = (int)1e9 + 1;
const int MOD = (int)1e9 + 7;
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string n;
  int k;
  cin >> n;
  cin >> k;
  int di = n.length();
  vint lab;
  vint p;
  for (int i = 0; i < (di); i++) {
    if (n[i] != 0) {
      p.push_back(n[i] - '0');
      lab.push_back(i);
      if (p.size() == 3) break;
    }
  }
  int num = lab.size();
  if (k == 1) {
    cout << (di - 1) * 9 + p[0] << endl;
  } else if (k == 2) {
    if (num >= 2) {
      cout << (di - 1) * (di - 2) / 2 * 9 * 9 + (p[0] - 1) * (di - 1) * 9 +
                  (di - lab[1] - 1) * 9 + p[1]
           << endl;
    } else {
      cout << (di - 1) * (di - 2) / 2 * 9 * 9 + (p[0] - 1) * (di - 1) * 9
           << endl;
    }
  } else if (k == 3) {
    if (num >= 3) {
      cout << (di - 1) * (di - 2) * (di - 3) / 6 * 9 * 9 * 9 +
                  (p[0] - 1) * (di - 1) * (di - 2) / 2 * 9 * 9 +
                  (p[1] - 1) * (di - lab[1] - 1) * 9 +
                  (di - lab[1] - 1) * (di - lab[1] - 2) / 2 * 9 * 9 + p[2] +
                  (di - lab[2] - 1) * 9
           << endl;
    } else if (num == 2) {
      cout << (di - 1) * (di - 2) * (di - 3) / 6 * 9 * 9 * 9 +
                  (p[0] - 1) * (di - 1) * (di - 2) / 2 * 9 * 9 +
                  (p[1] - 1) * (di - lab[1] - 1) * 9 +
                  (di - lab[1] - 1) * (di - lab[1] - 2) / 2 * 9 * 9 + 1
           << endl;
    } else if (num == 1) {
      cout << (di - 1) * (di - 2) * (di - 3) / 6 * 9 * 9 * 9 +
                  (p[0] - 1) * (di - 1) * (di - 2) / 2 * 9 * 9 + 1
           << endl;
    }
  }
  return 0;
}
