#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 1;
int n, k, cnt, mark[322], mx, m, uncp, unct, l;
string s, was;
char flag;
pair<int, char> pp[M];
int main() {
  cin >> s >> k;
  n = (int)s.size();
  if (k >= n) {
    cout << 0 << "\n";
    cout << "";
    return 0;
  }
  for (int i = 0; i < n; i++) {
    mark[(int)s[i]]++;
  }
  for (int i = 'a'; i <= 'z'; i++) {
    if (mark[i] != 0) pp[cnt++] = make_pair(mark[i], i);
  }
  sort(pp, pp + cnt);
  for (int i = 0; i <= cnt; i++) {
    if (pp[i].first <= k) {
      k -= pp[i].first;
      was += pp[i].second;
    } else {
      unct = pp[i].first - k;
      uncp = i;
      break;
    }
  }
  cerr << was;
  cnt = 0;
  l = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == uncp && unct) {
      s[i] = '.';
      unct--;
    } else if (was.find(s[i]) != string::npos) {
      s[i] = '.';
    }
  }
  memset(mark, 0, sizeof(mark));
  for (int i = 0; i < n; i++) {
    if (!mark[(int)s[i]] && s[i] != '.') m++;
    mark[(int)s[i]] = 1;
  }
  cout << m << "\n";
  for (int i = 0; i < n; i++) {
    if (s[i] != '.') cout << s[i];
  }
  return 0;
}
