#include <bits/stdc++.h>
using namespace std;
int ToInt(string& s, int len) {
  int r = 0;
  for (int i = 0, max_ = (len); i < max_; ++i) {
    r *= 10;
    r += s[i] - '0';
  }
  return r;
}
int GCD(int a, int b) { return b != 0 ? GCD(b, a % b) : a; }
int LCM(int a, int b) { return a * (b / GCD(a, b)); }
long long Pow(long long n, long long e) {
  if (e == 0) return 1;
  if (e == 1)
    return n;
  else if (e & 1) {
    long long t = Pow(n, e / 2);
    return n * t * t;
  } else {
    long long t = Pow(n, e / 2);
    return t * t;
  }
}
pair<int, char> v[26];
bool toRem[26];
int main() {
  string s;
  getline(cin, s);
  int K;
  scanf("%d", &K);
  for (int i = 0, max_ = (26); i < max_; ++i) v[i].second = 'a' + i;
  for (int i = 0, max_ = ((int)(s).size()); i < max_; ++i)
    ++v[s[i] - 'a'].first;
  sort(v, v + 26);
  int j = 0, rem = 26;
  while (j < 26) {
    if (K < v[j].first) break;
    toRem[v[j].second - 'a'] = true;
    K -= v[j].first;
    --rem;
    ++j;
  }
  printf("%d\n", rem);
  for (int i = 0, max_ = ((int)(s).size()); i < max_; ++i)
    if (!toRem[s[i] - 'a']) printf("%c", s[i]);
  return 0;
}
