#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
string s;
long long k;
map<char, long long> m;
vector<pair<long long, char> > v;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> s >> k;
  for (auto &it : s) m[it]++;
  for (auto &it : m) v.push_back({it.second, it.first});
  sort(v.begin(), v.end());
  set<char> erased;
  for (auto &it : v) {
    if (k - it.first >= 0) {
      erased.insert(it.second);
      k -= it.first;
    } else
      break;
  }
  cout << m.size() - erased.size() << "\n";
  for (auto &it : s) {
    if (erased.find(it) == erased.end()) cout << it;
  }
  return 0;
}
