#include <bits/stdc++.h>
using namespace std;
int n, k;
string s;
vector<int> cnt;
vector<pair<int, char> > data;
bool to_remove[26];
int main() {
  cin >> s >> k;
  cnt.assign(26, 0);
  for (int i = 0; i < s.size(); i++) cnt[s[i] - 'a']++;
  for (int i = 0; i < 26; i++)
    if (cnt[i] != 0) data.push_back(make_pair(cnt[i], i));
  sort(data.begin(), data.end());
  for (int i = 0; i < data.size(); i++) {
    if (k >= data[i].first) {
      k -= data[i].first;
      to_remove[data[i].second] = true;
    }
  }
  int diff = 0, tr = 0;
  for (int i = 0; i < 26; i++) diff += (cnt[i] != 0);
  for (int i = 0; i < 26; i++) tr += to_remove[i];
  cout << diff - tr << endl;
  for (int i = 0; i < s.size(); i++)
    if (!to_remove[s[i] - 'a']) cout << s[i];
  return 0;
}
