#include <bits/stdc++.h>
using namespace std;
int cnt[128];
int n, k, out;
char x[100100];
bool rem[128];
int main() {
  scanf("%s", &x);
  n = strlen(x);
  scanf("%d", &k);
  for (int i = 0; i < n; ++i) ++cnt[x[i]], out += (cnt[x[i]] == 1);
  for (int j = 0; j < 26; ++j) {
    int mn = 1e9, c;
    for (int i = 'a'; i <= 'z'; ++i) {
      if (cnt[i] && cnt[i] < mn) mn = cnt[i], c = i;
    }
    if (mn <= k) k -= mn, rem[c] = 1, cnt[c] = 1e9, --out;
  }
  printf("%d\n", out);
  for (int i = 0; i < n; ++i)
    if (!rem[x[i]]) printf("%c", x[i]);
}
