#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int n;
  cin >> s >> n;
  int a[26] = {0}, to = 0;
  vector<pair<int, char> > b;
  for (int i = 0; i < s.size(); i++) a[s[i] - 'a']++;
  for (int i = 0; i < 26; i++) {
    if (a[i]) {
      b.push_back({a[i], i + 'a'});
      to++;
    }
  }
  sort(b.begin(), b.end());
  for (int i = 0; i < b.size(); i++) {
    if (b[i].first <= n) {
      a[b[i].second - 'a'] = 0;
      n -= b[i].first;
      to--;
    }
  }
  cout << to << endl;
  for (int i = 0; i < s.size(); i++)
    if (a[s[i] - 'a']) cout << s[i];
  return 0;
}
