#include <bits/stdc++.h>
using namespace std;
const long long inf = long long(1e18) + 1;
int main() {
  string n;
  int k;
  cin >> n >> k;
  int ans = 0;
  int a = n.size();
  if (k == 1) {
    ans = 9 * (a - 1);
    ans += n[0] - '0';
  } else if (k == 2) {
    if (a < k) {
      cout << 0 << endl;
      return 0;
    }
    for (int i = 2; i <= a - 1; i++) {
      ans += 9 * (9 * (i - 1));
    }
    int b = (n[0] - '0');
    ans += b * (9 * (a - 1));
    int c = (n[1] - '0');
    ans -= (9 - c);
  } else {
    if (a < k) {
      cout << 0 << endl;
      return 0;
    }
    for (int i = 3; i <= a - 1; i++) {
      ans += 729 * (i - 1) * (i - 2) / 2;
    }
    int b = (n[0] - '0');
    ans += 81 * b * (a - 1) * (a - 2) / 2;
    int c = (n[1] - '0');
    int d = (n[2] - '0');
    ans -= (9 * (9 - c) + 9 - d);
  }
  cout << ans << endl;
  return 0;
}
