#include <bits/stdc++.h>
using namespace std;
string Erase(const string& s, char ch) {
  string ret;
  for (size_t i = 0; i < s.size(); i++)
    if (s[i] != ch) ret += s[i];
  return ret;
}
int main() {
  string s;
  int k;
  cin >> s;
  cin >> k;
  map<char, int> charcounts;
  for (size_t i = 0; i < s.size(); i++) charcounts[s[i]]++;
  vector<pair<int, char> > counts;
  for (map<char, int>::iterator p = charcounts.begin(); p != charcounts.end();
       p++)
    counts.push_back(make_pair(p->second, p->first));
  sort(counts.begin(), counts.end());
  while (!counts.empty() && k - counts.begin()->first >= 0) {
    k -= counts.begin()->first;
    s = Erase(s, counts.begin()->second);
    counts.erase(counts.begin());
  }
  cout << counts.size() << endl;
  cout << s << endl;
  return 0;
}
