#include <bits/stdc++.h>
using namespace std;
static int fast_io = []() {
  std::ios::sync_with_stdio(false);
  cin.tie(nullptr);
  return 0;
}();
struct charA {
  int amount;
  char c;
  bool operator<(const charA& rhs) const { return amount > rhs.amount; }
};
int main() {
  string s;
  int n;
  cin >> s >> n;
  vector<int> occurences(26);
  for (auto x : s) {
    ++occurences[x - 'a'];
  }
  priority_queue<charA> pq;
  for (int i = 0; i < 26; i++) {
    pq.push(charA{occurences[i], char('a' + i)});
  }
  while (pq.size() > 0 && n > 0) {
    if (pq.top().amount > n) {
      break;
    } else {
      n -= pq.top().amount;
      occurences[pq.top().c - 'a'] = 0;
      pq.pop();
    }
  }
  int diffAmount = 0;
  for (int i = 0; i < 26; i++) {
    if (occurences[i] > 0) diffAmount++;
  }
  cout << diffAmount << endl;
  for (auto x : s) {
    if (occurences[x - 'a'] > 0) {
      cout << x;
      --occurences[x - 'a'];
    }
  }
  return 0;
}
