#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int OO = 1e9;
int A[N];
int B[N];
int x, n, a, n2, k, b, q, xx, t, m, l, c, fn;
string s, s2, s3;
vector<pair<int, char> > v;
bitset<50000> isprime;
int solve(int c, int mn) {
  if (c == n) return 1;
  int op1 = 1e9, op2 = 1e9, ret = 1e9;
  for (int i = 1; i < n; i++) {
    if (!B[i]) {
      B[i] = 1;
      if (mn > 0)
        op1 = solve(c + 1, min(mn - 1, A[i]));
      else
        op2 = solve(c + 1, A[i]) + 1;
      B[i] = 0;
    }
  }
  return min(op1, op2);
}
int main() {
  cin >> s;
  cin >> k;
  map<char, int> mp;
  if (k >= s.size()) return cout << 0 << endl, 0;
  for (int i = 0; i < s.size(); i++) mp[s[i]]++;
  for (auto i = mp.begin(); i != mp.end(); i++) {
    char a = i->first;
    int b = i->second;
    v.push_back({b, a});
  }
  sort(v.rbegin(), v.rend());
  int stop = 0;
  int sign = 0;
  for (int i = 0; i < v.size(); i++) {
    c += v[i].first;
    sign++;
    if (k >= s.size() - c) {
      stop += v[i].first - (k - s.size() + c);
      A[v[i].second - 'a'] = v[i].first - (k - s.length() + c);
      break;
    }
    A[v[i].second - 'a'] = v[i].first;
    stop += v[i].first;
  }
  cout << sign << endl;
  for (int i = 0; i < s.size() && stop; i++) {
    if (A[s[i] - 'a']) {
      cout << s[i];
      stop--;
      A[s[i] - 'a']--;
    }
  }
  return 0;
}
