#include <bits/stdc++.h>
using namespace std;
char s[100100];
int was[30];
vector<pair<int, int> > a;
int del[30];
int main() {
  scanf("%s", &s);
  int n = strlen(s);
  for (int i = (0); i < (n); ++i) was[s[i] - 'a']++;
  for (int i = (0); i < (26); ++i)
    if (was[i]) a.push_back(make_pair(was[i], i));
  sort(a.begin(), a.end());
  int k;
  cin >> k;
  for (int i = (0); i < (a.size()); ++i) {
    if (a[i].first > k) break;
    k -= a[i].first;
    del[a[i].second] = 1;
  }
  int res = 0;
  for (int i = (0); i < (26); ++i)
    if ((was[i] > 0) && (del[i] == 0)) res++;
  cout << res << endl;
  for (int i = (0); i < (n); ++i) {
    int v = s[i] - 'a';
    if (del[v] == 0) printf("%c", s[i]);
  }
  printf("\n");
  return 0;
}
