#include <bits/stdc++.h>
using namespace std;
bool cmp(int a, int b) { return a > b; }
bool taken[260];
bool remo[260];
int main() {
  string x;
  cin >> x;
  int dist = 0, k;
  cin >> k;
  map<char, int> mpp;
  for (int i = 0; i < x.size(); i++) {
    if (!taken[x[i]]) taken[x[i]] = 1, dist++;
    mpp[x[i]]++;
  }
  vector<pair<int, char> > occ;
  for (map<char, int>::iterator it = mpp.begin(); it != mpp.end(); it++)
    occ.push_back(make_pair(it->second, it->first));
  int removed = 0;
  sort(occ.begin(), occ.end());
  for (int i = 0; i < occ.size() && occ[i].first <= k; i++) {
    k -= occ[i].first;
    remo[occ[i].second] = 1;
    removed++;
  }
  cout << dist - removed << endl;
  for (int i = 0; i < x.size(); i++)
    if (!remo[x[i]]) cout << x[i];
  return 0;
}
