#include <bits/stdc++.h>
#pragma GCC optimize("O3")
const int inf = INT_MAX;
const int nmax = 1e5 + 5;
const int mod = 1e9 + 7;
using namespace std;
string s;
int i, k, a[123], n, destroy[123], nr;
pair<int, char> p[27];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cerr.tie(0);
  cout.tie(0);
  cin >> s >> k;
  for (i = 0; i < s.length(); i++) a[s[i]]++;
  for (i = 'a'; i <= 'z'; i++)
    if (a[i]) p[++n].first = a[i], p[n].second = (char)i;
  sort(p + 1, p + n + 1);
  nr = n;
  for (i = 1; i <= n; i++) {
    if (k - p[i].first >= 0)
      destroy[p[i].second] = 1, nr--;
    else
      break;
    k -= p[i].first;
  }
  cout << nr << endl;
  for (i = 0; i < s.length(); i++)
    if (!destroy[s[i]]) cout << s[i];
  cout << endl;
  return 0;
}
