#include <bits/stdc++.h>
using namespace std;
int n, k;
string s;
bool b[26];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> s >> k;
  n = s.size();
  vector<pair<int, char>> v;
  int cnt[26] = {};
  for (char c : s) {
    cnt[c - 'a']++;
    b[c - 'a'] = 1;
  }
  int ans = 0;
  for (int i = 0; i < 26; i++) {
    if (cnt[i]) {
      v.emplace_back(cnt[i], i + 'a');
      ans++;
    }
  }
  sort(v.begin(), v.end());
  for (auto p : v) {
    if (k >= p.first) {
      ans--;
      b[p.second - 'a'] = 0;
      k -= p.first;
    }
  }
  cout << ans << '\n';
  for (char c : s) {
    if (b[c - 'a']) cout << c;
  }
  cout << '\n';
  return 0;
}
