#include <bits/stdc++.h>
#pragma comment(linker, "/stack:64000000")
using namespace std;
int v[26] = {0};
int del[26] = {0};
int main() {
  string s;
  cin >> s;
  int n;
  cin >> n;
  for (int(i) = 0; (i) < ((int)(s).size()); (i)++) v[s[i] - 'a']++;
  vector<pair<int, int> > w;
  for (int(i) = 0; (i) < (26); (i)++) {
    if (v[i] != 0) w.push_back(make_pair(v[i], i));
  }
  sort((w).begin(), (w).end());
  int t = 0;
  for (int(i) = 0; (i) < ((int)(w).size()); (i)++) {
    if (w[i].first <= n)
      del[w[i].second] = w[i].first, n -= w[i].first;
    else {
      del[w[i].second] = n;
      t = (int)(w).size() - i;
      break;
    }
  }
  cout << t << "\n";
  string r;
  for (int(i) = 0; (i) < ((int)(s).size()); (i)++) {
    if (del[s[i] - 'a'] > 0)
      del[s[i] - 'a']--;
    else
      r += s[i];
  }
  cout << r << "\n";
  return 0;
}
