#include <bits/stdc++.h>
using namespace std;
int arr[26];
int main() {
  string s;
  int k;
  cin >> s >> k;
  for (int i = 0; i < s.length(); i++) {
    arr[s[i] - 'a']++;
  }
  vector<pair<int, char>> v;
  for (int i = 0; i < 26; i++)
    if (arr[i]) v.push_back({arr[i], i + 'a'});
  sort(v.begin(), v.end());
  vector<char> ig;
  for (int i = 0; i < v.size(); i++) {
    if (k <= 0) break;
    if (v[i].first <= k) {
      k -= v[i].first;
      ig.push_back(v[i].second);
    } else
      break;
  }
  cout << v.size() - ig.size() << endl;
  for (int i = 0; i < s.length(); i++) {
    if (find(ig.begin(), ig.end(), s[i]) == ig.end()) cout << s[i];
  }
}
