#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string str;
  cin >> str;
  long long k;
  cin >> k;
  map<char, long long> mp;
  for (char ch : str) {
    mp[ch]++;
  }
  vector<pair<long long, char>> vp;
  for (auto it : mp) {
    vp.push_back({it.second, it.first});
  }
  sort(vp.begin(), vp.end());
  for (auto &it : vp) {
    if (k == 0) {
      break;
    }
    if (it.first <= k) {
      k = k - it.first;
      it.first = 0;
    } else {
      it.first = it.first - k;
      k = 0;
    }
  }
  mp.clear();
  for (auto it : vp) {
    if (it.first > 0) {
      mp[it.second] = it.first;
    }
  }
  string ans = "";
  for (char ch : str) {
    if (mp.find(ch) != mp.end() && mp[ch] > 0) {
      ans += ch;
      mp[ch]--;
    }
  }
  cout << mp.size() << "\n" << ans << "\n";
  return 0;
}
