#include <bits/stdc++.h>
using namespace std;
int main() {
  string str;
  int K;
  cin >> str;
  cin >> K;
  string tmp = str;
  multimap<int, char> tab;
  int all = 0;
  for (char c = 'a'; c <= 'z'; c++) {
    int cnt = count(str.begin(), str.end(), c);
    if (cnt > 0) all++;
    tab.insert(pair<int, char>(cnt, c));
  }
  multimap<int, char>::iterator it;
  vector<char> del;
  int dc = 0;
  for (it = tab.lower_bound(1); it != tab.end(); it++)
    if (it->first <= K) {
      dc++;
      K -= it->first;
      del.push_back(it->second);
    } else {
      break;
    }
  cout << all - dc << endl;
  for (int i = 0; i < str.size(); i++)
    if (find(del.begin(), del.end(), str[i]) == del.end()) cout << str[i];
  cout << endl;
}
