#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int INF = 0x3f3f3f3f;
const double PI = 3.1415926535;
int main() {
  string n;
  int k;
  cin >> n;
  cin >> k;
  int len = n.size();
  if (len <= 8) {
    int num = 0, ans = 0;
    for (int i = 0; i < len; ++i) {
      num *= 10;
      num += n[i] - '0';
    }
    for (int i = 1; i <= num; ++i) {
      int t = i, cnt = 0;
      while (t > 0) {
        if (t % 10 != 0) cnt++;
        t /= 10;
      }
      if (cnt == 2 && k == 2 || cnt == 3 && k == 3 || cnt == 1 && k == 1) ans++;
    }
    cout << ans << endl;
  } else {
    if (k == 1) {
      long long ans = (len - 1) * 9;
      ans += n[0] - '0';
      cout << ans << endl;
    } else if (k == 2) {
      long long ans = (len - 1) * (len - 2) / 2 * 81;
      ans += (n[0] - '0' - 1) * 9 * (len - 1);
      int in = 1;
      while (n[in] == '0') in++;
      ans += n[in] - '0';
      ans += 9 * (len - in - 1);
      cout << ans << endl;
    } else if (k == 3) {
      long long ans = (len - 1) * (len - 2) * (len - 3) / 6 * 729;
      ans += (n[0] - '0' - 1) * 81 * (len - 1) * (len - 2) / 2;
      int in = 1;
      while (n[in] == '0') in++;
      int in2 = in + 1;
      while (n[in2] == '0') in2++;
      ans += (n[in2] - '0');
      ans += (9 * (len - in2 - 1));
      ans += (len - in - 1) * (len - in - 2) / 2 * 81;
      ans += (n[in] - '0' - 1) * 9 * (len - in - 1);
      cout << ans << endl;
    }
  }
  return 0;
}
