#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  int fr[26] = {};
  for (int i = 0; i < s.size(); ++i) {
    fr[int(s[i] - 'a')]++;
  }
  int c = 0;
  vector<pair<int, char> > v;
  for (int i = 0; i < 26; ++i) {
    if (fr[i]) {
      char ch = char(i + int('a'));
      v.push_back(make_pair(fr[i], ch));
    }
  }
  sort(v.begin(), v.end());
  string ans = "";
  bool vis[26] = {};
  for (int i = 0; i < v.size(); ++i) {
    if (k >= v[i].first)
      k -= v[i].first;
    else {
      c++;
      vis[int(v[i].second) - 'a']++;
    }
  }
  for (int i = 0; i < s.size(); ++i) {
    if (vis[int(s[i]) - 'a']) ans += s[i];
  }
  cout << c << endl << ans << endl;
}
