#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int oo = (int)1e9;
const int mod = (int)1e9 + 7;
const int maxn = 1e5 + 1;
int dr[] = {0, 0, 1, -1};
int dc[] = {1, -1, 0, 0};
void myMain() {
  string s;
  cin >> s;
  int k;
  cin >> k;
  map<char, int> frq;
  for (auto i : s) frq[i]++;
  vector<pair<int, char>> a;
  for (auto i : frq) {
    a.push_back(make_pair(i.second, i.first));
  }
  sort(a.begin(), a.end());
  set<char> deleted;
  for (auto i : a) {
    if (k - i.first >= 0) {
      k -= i.first;
      deleted.insert(i.second);
    } else {
      break;
    }
  }
  cout << frq.size() - deleted.size() << '\n';
  for (auto i : s) {
    if (deleted.count(i)) continue;
    cout << i;
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  int testcases = 1;
  while (testcases--) {
    myMain();
  }
}
