#include <bits/stdc++.h>
using namespace std;
string ins;
int main() {
  cin >> ins;
  int k;
  cin >> k;
  int len = ins.size();
  int table[30];
  set<char> sc;
  memset(table, 0, sizeof table);
  for (int i = 0; i < len; i++) table[ins[i] - 'a']++, sc.insert(ins[i]);
  vector<pair<int, char> > vs;
  for (int i = 0; i < 26; i++)
    if (table[i]) vs.push_back(pair<int, int>(-table[i], i));
  sort(vs.begin(), vs.end());
  bool rm[30];
  int rms = 0;
  memset(rm, false, sizeof rm);
  while (k && vs.size()) {
    if (k < -vs.back().first) break;
    rm[vs.back().second] = true;
    k += vs.back().first;
    vs.pop_back();
    rms++;
  }
  cout << ((int)(sc.size())) - rms << endl;
  for (int i = 0; i < len; i++) {
    if (rm[ins[i] - 'a'])
      continue;
    else
      cout << ins[i];
  }
  cout << endl;
}
