#include <bits/stdc++.h>
using namespace std;
char a[100000];
int w[27];
char r[27];
void sort(int n) {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n - 1; j++) {
      if (w[j] > w[j + 1]) {
        swap(r[j], r[j + 1]);
        swap(w[j], w[j + 1]);
      }
    }
  }
}
int main() {
  cin >> a;
  int m;
  cin >> m;
  int n = strlen(a);
  if (m >= n) {
    cout << 0;
    return 0;
  }
  int j;
  int u = 0;
  for (int i = 0; i < n; i++) {
    for (j = 0; j < 26; j++) {
      if (j > u) u = j;
      if (a[i] == r[j]) {
        w[j]++;
        j++;
        break;
      }
      if (w[j] == 0) {
        w[j]++;
        r[j] = a[i];
        j++;
        break;
      }
    }
  }
  u++;
  sort(u);
  int sum = 0;
  int e = 0;
  while (sum <= m) {
    sum = sum + w[e];
    e++;
  }
  int o = 0;
  sum = sum - w[e - 1];
  cout << u - (e - 1) << endl;
  for (int i = 0; i < n; i++) {
    for (int p = 0; p < e - 1; p++) {
      if (a[i] == r[p]) o = 1;
    }
    if (o == 0)
      cout << a[i];
    else
      o = 0;
  }
}
