#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
struct node {
  char a;
  int num;
} a[maxn];
char tp[maxn];
int cc[maxn], choose[maxn], vis[maxn];
int cmp(node a, node b) { return a.num < b.num; }
int main() {
  while (scanf("%s", tp) != EOF) {
    int k;
    scanf("%d", &k);
    int len = strlen(tp);
    if (k >= len) {
      printf("0\n");
      continue;
    }
    memset(cc, 0, sizeof(cc));
    memset(choose, 0, sizeof(choose));
    for (int i = 0; i < len; i++) {
      a[i].a = tp[i];
      cc[tp[i] - 'a']++;
    }
    for (int i = 0; i < len; i++) {
      a[i].num = cc[tp[i] - 'a'];
    }
    int cnt = 0;
    sort(a, a + len, cmp);
    char flag = '@';
    for (int i = 0; i < len && cnt < k; i++) {
      if (cnt + a[i].num <= k && choose[a[i].a - 'a'] == 0) {
        cnt += a[i].num;
        choose[a[i].a - 'a'] = 1;
      } else if (cnt + a[i].num > k && choose[a[i].a - 'a'] == 0) {
        cnt = k;
        choose[a[i].a - 'a'] = 1;
        flag = a[i].a;
      }
    }
    int m = 0;
    memset(vis, 0, sizeof(vis));
    for (int i = 0; i < len; i++) {
      if (flag == tp[i] && vis[tp[i] - 'a'] == 0) {
        vis[tp[i] - 'a'] = 1;
        m++;
      } else if (choose[tp[i] - 'a'] == 0 && vis[tp[i] - 'a'] == 0) {
        vis[tp[i] - 'a'] = 1;
        m++;
      }
    }
    printf("%d\n", m);
    for (int i = 0; i < len; i++) {
      if (choose[tp[i] - 'a'] == 0 || flag == tp[i]) {
        printf("%c", tp[i]);
      }
    }
    printf("\n");
  }
  return 0;
}
