#include <bits/stdc++.h>
using namespace std;
string s;
int n;
int a[100], k[100], le[100];
void qsort(int l, int r) {
  int i, j, x, y;
  i = l;
  j = r;
  x = k[(l + r) / 2];
  do {
    while (k[i] < x) i++;
    while (k[j] > x) j--;
    if (i <= j) {
      y = k[i];
      k[i] = k[j];
      k[j] = y;
      y = le[i];
      le[i] = le[j];
      le[j] = y;
      i++;
      j--;
    }
  } while (i <= j);
  if (l < j) qsort(l, j);
  if (i < r) qsort(i, r);
}
int main() {
  cin >> s;
  cin >> n;
  for (int i = 0; i < s.length(); i++) {
    a[s[i] - 'a']++;
  }
  int top = 0;
  for (int i = 0; i < 26; i++) {
    if (a[i] > 0) {
      k[top] = a[i];
      le[top] = i;
      top++;
    }
  }
  top--;
  qsort(0, top);
  int temp = 0;
  int ans = top + 1;
  while (n > 0) {
    if (n >= k[temp]) {
      n -= k[temp];
      a[le[temp]] = -k[temp];
      ans--;
    } else {
      n = 0;
    }
    temp++;
    if (temp > top) {
      break;
    }
  }
  cout << ans << endl;
  for (int i = 0; i < s.length(); i++) {
    if (a[s[i] - 'a'] >= 0) {
      cout << s[i];
    } else {
      a[s[i] - 'a']++;
    }
  }
  cout << endl;
  return 0;
}
