#include <bits/stdc++.h>
using namespace std;
int stmp;
const int maxn = 100100;
char buf[maxn];
int n, k;
vector<pair<int, char> > stats;
bool u[maxn];
bool c[2230];
int p[4000];
void rs() {
  printf("stats\n");
  for (int(i) = 0; (i) < int(stats.size()); (i)++)
    printf("%d %d %c\n", i, stats[i].first, stats[i].second);
}
int main() {
  stmp = scanf("%s %d", buf, &k);
  n = strlen(buf);
  for (int(i) = 0; (i) < int('z' - 'a' + 1); (i)++)
    stats.push_back(make_pair(0, 'a' + i));
  for (int(i) = 0; (i) < int(n); (i)++) stats[buf[i] - 'a'].first++;
  sort(stats.begin(), stats.end());
  if (0) rs();
  for (int(i) = 0; (i) < int(stats.size()); (i)++) {
    stats[i].first = min(stats[i].first, k);
    k -= stats[i].first;
  }
  if (0) rs();
  for (int(i) = 0; (i) < int('z' - 'a' + 1); (i)++) c['a' + i] = 0;
  for (int(i) = 0; (i) < int(stats.size()); (i)++) p[stats[i].second] = i;
  for (int(i) = 0; (i) < int(n); (i)++) {
    if (stats[p[buf[i]]].first) {
      stats[p[buf[i]]].first--;
      u[i] = 0;
    } else {
      u[i] = 1;
      c[buf[i]] = 1;
    }
  }
  int m = 0;
  for (int(i) = 0; (i) < int('z' - 'a' + 1); (i)++)
    if (c['a' + i]) m++;
  printf("%d\n", m);
  for (int(i) = 0; (i) < int(n); (i)++)
    if (u[i]) putchar(buf[i]);
  putchar('\n');
  return 0;
}
