#include <bits/stdc++.h>
using namespace std;
int n, m, ans, le, ri;
struct node {
  int x, y, id;
} p[100005];
bool cmp(node a, node b) {
  if (a.x != b.x) return a.x < b.x;
  if (a.x == 1) return a.y < b.y;
  if (a.x == 2) return a.y > b.y;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d", &p[i].x, &p[i].y);
    p[i].id = i;
  }
  sort(p + 1, p + 1 + n, cmp);
  int l = 1, r = 1, tot = 0, sum = 0;
  while (r <= n) {
    while (r <= n && tot <= m) {
      tot += p[r].x;
      sum += p[r].y;
      if (tot <= m && sum > ans) {
        ans = sum;
        le = l;
        ri = r;
      }
      r++;
    }
    while (tot > m) {
      tot -= p[l].x;
      sum -= p[l].y;
      l++;
      if (tot <= m && sum > ans) {
        ans = sum;
        le = l;
        ri = r - 1;
      }
    }
  }
  printf("%d\n", ans);
  if (ri)
    for (int i = le; i <= ri; i++) printf("%d ", p[i].id);
  return 0;
}
