#include <bits/stdc++.h>
using namespace std;
long long int mod = 1e9 + 7;
const double error = 1e-7;
const double PI = acos(-1);
mt19937_64 rng(
    (unsigned int)chrono::system_clock::now().time_since_epoch().count());
inline long long int MOD(long long int x, long long int m = mod) {
  long long int y = x % m;
  return (y >= 0) ? y : y + m;
}
const int inf = 1e9 + 5;
const long long int infl = 1e18 + 1;
const int nmax = 1e6 + 5;
char str[nmax];
int freq[128];
bool del[128];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  cin >> str;
  int k;
  cin >> k;
  for (int i = 0; str[i] != 0; i++) {
    freq[str[i]]++;
  }
  vector<pair<int, char> > tmp;
  for (int i = 'a'; i <= 'z'; i++) tmp.emplace_back(freq[i], char(i));
  sort(tmp.begin(), tmp.end());
  int used = 0;
  for (int i = 0; i < 26; i++) {
    if (used + tmp[i].first <= k) {
      used += tmp[i].first;
      del[tmp[i].second] = true;
    }
  }
  int ans = 0;
  for (int i = 'a'; i <= 'z'; i++) {
    if (freq[i] > 0 && !del[i]) ans++;
  }
  cout << ans << "\n";
  for (int i = 0; str[i] != 0; i++)
    if (!del[str[i]]) cout << str[i];
  return 0;
}
