#include <bits/stdc++.h>
using namespace std;
const long long MOD = 4294967296, INF = 2E18 + 5;
const double PI = 2 * acos(0.0);
const long double EPS = 1.0E-14;
vector<pair<char, long long> > vec;
map<char, long long> mp;
bool comp(const pair<char, long long> &A, const pair<char, long long> &B) {
  return A.second < B.second;
}
int main() {
  string s, ans = "";
  long long k, val, ansCnt = 0;
  cin >> s >> k;
  for (int i = 0; i < s.size(); i++) {
    mp[s[i]]++;
  }
  for (auto it = mp.begin(); it != mp.end(); it++) {
    vec.push_back({it->first, it->second});
  }
  sort(vec.begin(), vec.end(), comp);
  for (int i = 0; i < vec.size(); i++) {
    val = min(k, vec[i].second);
    k -= val, vec[i].second -= val;
    mp[vec[i].first] -= val;
  }
  for (auto it = mp.begin(); it != mp.end(); it++) {
    if (it->second > 0) ansCnt++;
  }
  for (int i = 0; i < s.size(); i++) {
    if (mp[s[i]] > 0) {
      ans += s[i];
    }
  }
  cout << ansCnt << "\n" << ans;
  return 0;
}
