#include <bits/stdc++.h>
using namespace std;
struct Tnode {
  int sum, id;
} f[26];
char a[100000 + 2];
int flag[100000 + 2];
int cmp(struct Tnode f1, struct Tnode f2) { return f1.sum < f2.sum; }
void init() {
  memset(flag, 0, sizeof(flag));
  int len = strlen(a);
  for (int i = 0; i < 26; i++) {
    f[i].sum = 0;
    f[i].id = i;
  }
  for (int j = 0; j < len; j++) f[a[j] - 'a'].sum++;
  sort(f, f + 26, cmp);
}
void solve(int k) {
  int sum = 0;
  for (int p = 0; p < 26; p++) {
    if (f[p].sum) sum++;
  }
  for (int i = 0; i < 26; i++) {
    if (f[i].sum) {
      int s = f[i].sum;
      if (s <= k) {
        k -= s;
        for (int j = 0; a[j] != '\0'; j++) {
          if (a[j] - 'a' == f[i].id) flag[j] = 1;
        }
        sum--;
      } else {
        for (int z = 0; k; z++) {
          if (a[z] - 'a' == f[i].id) {
            flag[z] = 1;
            k--;
          }
        }
        break;
      }
    }
  }
  printf("%d\n", sum);
  for (int q = 0; a[q] != '\0'; q++) {
    if (flag[q] == 0) printf("%c", a[q]);
  }
  printf("\n");
}
int main() {
  while (gets(a)) {
    int k;
    scanf("%d", &k);
    init();
    solve(k);
    getchar();
  }
  return 0;
}
