#include <bits/stdc++.h>
using namespace std;
string p1, p2;
int n, m, plat[30], vis[30], ans;
typedef struct point {
  int x, y;
} point;
point kk[30];
bool cmp(const point &a, const point &b) { return a.y < b.y; }
int main() {
  cin >> p1;
  n = p1.size();
  scanf("%d", &m);
  for (int i = 1; i <= 26; i++) kk[i].x = i;
  for (int i = 0; i < n; i++) plat[p1[i] - 'a' + 1]++;
  for (int i = 1; i <= 26; i++) kk[i].y = plat[i];
  sort(&kk[1], &kk[27], cmp);
  int i, j;
  for (i = 1; i <= 26; i++)
    if (kk[i].y != 0) break;
  for (int j = i; j <= 26; j++) {
    if (m - kk[j].y >= 0) {
      vis[kk[j].x] = 1;
      m = m - kk[j].y;
    } else
      break;
  }
  for (int j = i; j <= 26; j++)
    if (vis[kk[j].x] == 0) ans++;
  for (int i = 0; i < n; i++)
    if (!vis[p1[i] - 'a' + 1]) p2.append(1, p1[i]);
  printf("%d\n", ans);
  cout << p2 << endl;
}
