#include <bits/stdc++.h>
using namespace std;
int main(void) {
  string s;
  cin >> s;
  int k;
  cin >> k;
  vector<pair<int, char> > vec;
  map<char, int> mp;
  for (int i = 0; i < s.size(); i++) {
    mp[s[i]]++;
  }
  for (map<char, int>::iterator it = mp.begin(); it != mp.end(); it++) {
    vec.push_back(make_pair(it->second, it->first));
  }
  sort(vec.begin(), vec.end());
  map<char, bool> exists;
  int n = 0;
  for (int i = 0; i < vec.size(); i++) {
    if (vec[i].first <= k) {
      k -= vec[i].first;
      exists[vec[i].second] = true;
      n++;
    }
  }
  cout << (int)vec.size() - n;
  cout << "\n";
  for (int i = 0; i < s.size(); i++) {
    if (!exists[s[i]]) cout << s[i];
  }
}
