#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b) {
  long long ans = 1;
  for (long long i = 1; i <= b; i++) {
    ans *= a;
  }
  return ans;
}
long long make(string p) {
  long long sum = 0, ck = 1;
  for (long long i = p.size() - 1; i >= 0; i--) {
    sum += (p[i] - '0') * ck;
    ck *= 10;
  }
  return sum;
}
struct Point {
  long long x, y, z;
} point[10000];
int main() {
  string s;
  cin >> s;
  long long m;
  cin >> m;
  map<char, long long> xx;
  map<char, long long>::iterator it;
  for (long long i = 0; i < s.size(); i++) {
    xx[s[i]]++;
  }
  if (m > s.size()) {
    cout << "0\n\n";
    return 0;
  }
  long long ppp = xx.size();
  pair<long long, char> pa[ppp];
  long long ck = 0;
  for (it = xx.begin(); it != xx.end(); it++, ck++) {
    pa[ck].first = it->second;
    pa[ck].second = it->first;
  }
  sort(pa, pa + xx.size());
  long long start = 0, sum = 0;
  for (long long i = 0; i < xx.size(); i++) {
    if (sum + pa[i].first <= m) {
      sum += pa[i].first;
    } else {
      start = i;
      break;
    }
    if (i == xx.size() - 1) start = i + 1;
  }
  if (xx.size() - start == 0) {
    cout << "0\n\n";
    return 0;
  }
  cout << xx.size() - start << endl;
  for (long long i = 0; i < start; i++) {
    xx[pa[i].second] = -1;
  }
  for (long long i = 0; i < s.size(); i++) {
    if (xx[s[i]] != -1) cout << s[i];
  }
}
