#include <bits/stdc++.h>
using namespace std;
int a[5555];
bool mark[5555];
char s[555555];
int main() {
  int n, k, i, j, br;
  gets(s);
  n = strlen(s);
  scanf("%d", &k);
  if (k >= n) {
    printf("0\n\n");
    return 0;
  }
  for (i = 0; i < 555; i++) {
    a[i] = 0;
    mark[i] = true;
  }
  br = 0;
  for (i = 0; i < n; i++) {
    a[int(s[i])]++;
    if (a[int(s[i])] == 1) br++;
    mark[int(s[i])] = false;
  }
  while (k) {
    j = -1;
    for (i = 'a'; i <= 'z'; i++)
      if (!mark[i] && (j == -1 || a[i] < a[j])) j = i;
    if (k >= a[j]) {
      mark[j] = true;
      k -= a[j];
      br--;
    } else
      k = 0;
  }
  printf("%d\n", br);
  for (i = 0; i < n; i++)
    if (!mark[int(s[i])]) printf("%c", s[i]);
  printf("\n");
  return 0;
}
