#include <bits/stdc++.h>
using namespace std;
const int MAXN = 8;
const int MAXR = 1;
const int MAXC = 1;
const int INF = (int)1e+9;
int arr[MAXN];
map<char, int> m;
int x4[] = {-1, 0, 1, 0};
int y4[] = {0, 1, 0, -1};
template <typename T1, typename T2>
struct less_second {
  bool operator()(pair<T1, T2> const& a, pair<T1, T2> const& b) const {
    return a.second < b.second;
  }
};
int main(void) {
  ios::sync_with_stdio(false);
  string s;
  int k;
  cin >> s;
  cin >> k;
  for (int i = 0; i < s.size(); i++) {
    m[s[i]]++;
  }
  vector<pair<char, int>> mc(m.begin(), m.end());
  sort(mc.begin(), mc.end(), less_second<char, int>());
  set<char> cs;
  for (vector<pair<char, int>>::iterator i = mc.begin(); i != mc.end(); i++) {
    if (k >= i->second) {
      cs.insert(i->first);
      k = k - (i->second);
      i->second = 0;
    } else {
      break;
    }
  }
  int cnt = 0;
  for (vector<pair<char, int>>::iterator i = mc.begin(); i != mc.end(); i++) {
    if (i->second != 0) {
      cnt++;
    }
  }
  cout << cnt << "\n";
  for (int i = 0; i < s.size(); i++) {
    if (cs.find(s[i]) == cs.end()) {
      cout << s[i];
    }
  }
  return 0;
}
