#include <bits/stdc++.h>
using namespace std;
const int oo = (int)1e9, MAXN = (int)1e6, risk = (int)1e6;
const double eps = 1e-9;
map<char, int> dic;
map<char, bool> mark;
map<char, bool> ANS;
char line[MAXN];
int main() {
  int n, k, ans;
  scanf("%s%d", &line, &k);
  n = strlen(line);
  ans = 0;
  for (int i = 0; i < (n); i++) {
    dic[line[i]]++;
    if (!ANS[line[i]]) {
      ANS[line[i]] = true;
      ans++;
    }
  }
  vector<pair<int, char> > t;
  for (typeof((dic).begin()) it = (dic).begin(); it != (dic).end(); it++)
    t.push_back(make_pair(it->second, it->first));
  sort((t).begin(), (t).end());
  reverse((t).begin(), (t).end());
  while (t.size() && t[t.size() - 1].first <= k) {
    mark[t[t.size() - 1].second] = true;
    if (ANS[t[t.size() - 1].second]) {
      ANS[t[t.size() - 1].second] = false;
      ans--;
    }
    k -= t[t.size() - 1].first;
    t.pop_back();
  }
  cout << ans << endl;
  for (int i = 0; i < (n); i++)
    if (!mark[line[i]]) cout << line[i];
  cout << endl;
  return 0;
}
