#include <bits/stdc++.h>
using namespace std;
typedef struct {
  int index;
  int p;
} node;
bool cmp(node a, node b) { return a.p > b.p; }
node a1[100005], a2[100005], s[100005];
int main() {
  int n, v;
  scanf("%d %d", &n, &v);
  int t;
  int t1 = 0, t2 = 0, t3 = 0;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &t);
    if (1 == t) {
      a1[t1].index = i;
      scanf("%d", &a1[t1].p);
      ++t1;
    } else {
      a2[t2].index = i;
      scanf("%d", &a2[t2].p);
      ++t2;
    }
  }
  sort(a1, a1 + t1, cmp);
  sort(a2, a2 + t2, cmp);
  int result = 0;
  int i1 = 0, i2 = 0;
  for (; i2 < t2; ++i2) {
    if (v < 2) break;
    s[t3++] = a2[i2];
    v -= 2;
  }
  for (; i1 < t1; ++i1) {
    if (0 == v) break;
    s[t3++] = a1[i1];
    --v;
  }
  --i2;
  while (i2 >= 0 && i1 < t1) {
    if (i1 + 1 == t1) {
      if (a1[i1].p > a2[i2].p) s[i2] = a1[i1];
    } else {
      if (a1[i1].p + a1[i1 + 1].p > a2[i2].p) {
        s[i2] = a1[i1];
        s[t3++] = a1[i1 + 1];
      }
    }
    i1 += 2;
    --i2;
  }
  for (int i = 0; i < t3; ++i) result += s[i].p;
  printf("%d\n", result);
  for (int i = 0; i < t3 - 1; ++i) printf("%d ", s[i].index);
  if (t3 > 0) printf("%d\n", s[t3 - 1].index);
  return 0;
}
