#include <bits/stdc++.h>
using namespace std;
bool mark[30];
int cnt[30];
pair<int, int> p[30];
int main() {
  string s;
  cin >> s;
  int k, m = 0;
  cin >> k;
  for (int i = 0; i < (int)s.size(); i++) {
    if (cnt[s[i] - 'a'] == 0) m++;
    cnt[s[i] - 'a']++;
  }
  for (int i = 0; i < 26; i++) p[i] = make_pair(cnt[i], i);
  sort(p, p + 26);
  for (int i = 0; i < 26; i++)
    if (p[i].first > 0 && k >= p[i].first) {
      k -= p[i].first;
      mark[p[i].second] = true;
      m--;
    }
  cout << m << endl;
  for (int i = 0; i < (int)s.size(); i++)
    if (!mark[s[i] - 'a']) cout << s[i];
  cout << endl;
  return 0;
}
