#include <bits/stdc++.h>
using namespace std;
int main() {
  string str;
  cin >> str;
  int k;
  cin >> k;
  if (k >= str.size()) {
    cout << 0;
    return 0;
  }
  vector<pair<int, char>> v(26);
  for (int i = 0; i < 26; i++) v[i] = make_pair(0, i + 'a');
  for (int i = 0; i < str.size(); i++) v[str[i] - 'a'].first++;
  sort(v.begin(), v.end());
  vector<bool> re(26);
  for (int i = 0; i < v.size(); i++) {
    if (v[i].first <= k) {
      k -= v[i].first;
      v[i].first = 0;
      re[v[i].second - 'a'] = true;
    } else
      break;
  }
  int q = v.size();
  for (int i = 0; i < 26; i++)
    if (v[i].first == 0) q--;
  cout << q << endl;
  for (int i = 0; i < str.size(); i++)
    if (re[str[i] - 'a'] == false) cout << str[i];
}
