#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  int n, ct1 = 0, ct2 = 0;
  cin >> s >> n;
  vector<pair<int, int>> vp;
  map<int, int> m;
  for (int i = 0; i < s.length(); i++) {
    m[s[i]]++;
  }
  for (auto itr : m) {
    vp.push_back({itr.second, itr.first});
  }
  sort(vp.begin(), vp.end());
  for (int i = 0; i < vp.size(); i++) {
    ct1++;
    if (n >= vp[i].first) {
      n -= vp[i].first;
      m[vp[i].second] = 0;
      ct2++;
    }
  }
  cout << ct1 - ct2 << "\n";
  for (int i = 0; i < s.length(); i++) {
    if (m[s[i]] != 0) cout << s[i];
  }
  cout << "\n";
}
