#include <bits/stdc++.h>
using namespace std;
struct node {
  int cap;
  int num;
};
node a1[100005], a2[100005];
int n, v;
int cmp(node a, node b) { return b.cap < a.cap; }
int main() {
  int maxt = 0, maxv = 0;
  scanf("%d %d", &n, &v);
  int i1, i2, i;
  for (i1 = 1, i2 = 1, i = 1; i <= n; i += 1) {
    int t, p;
    scanf("%d %d", &t, &p);
    maxt += t, maxv += p;
    if (t == 1)
      a1[i1].cap = p, a1[i1++].num = i;
    else
      a2[i2].cap = p, a2[i2++].num = i;
  }
  if (maxt <= v) {
    printf("%d\n", maxv);
    for (int i = 1; i <= n; i += 1) printf("%d ", i);
    printf("\n");
    return 0;
  }
  a1[0].cap = 0, a1[0].num = 0;
  a2[0].cap = 0, a2[0].num = 0;
  sort(a1 + 1, a1 + i1, cmp);
  sort(a2 + 1, a2 + i2, cmp);
  for (int i = 1; i < i1; i += 1) a1[i].cap = a1[i - 1].cap + a1[i].cap;
  for (int i = 1; i < i2; i += 1) a2[i].cap = a2[i - 1].cap + a2[i].cap;
  int ans = 0, ansi = 0, ansj = 0;
  for (int i = 0; i < i2 && i * 2 <= v; i += 1) {
    int j = v - 2 * i;
    if (j < i1 && ans < a2[i].cap + a1[j].cap) {
      ans = a2[i].cap + a1[j].cap;
      ansi = i;
      ansj = j;
    }
    if (j - 1 && j - 1 < i1 && ans < a2[i].cap + a1[j - 1].cap) {
      ans = a2[i].cap + a1[j - 1].cap;
      ansi = i;
      ansj = j - 1;
    }
  }
  if (i1 == 1)
    for (int i = i2; i >= 1; i -= 1)
      if (i * 2 <= v) {
        ans = a2[i].cap;
        ansi = i;
        ansj = 0;
        break;
      }
  if (i2 == 1)
    for (int i = i1; i >= 1; i -= 1)
      if (i <= v) {
        ans = a1[i].cap;
        ansi = 0;
        ansj = i;
        break;
      }
  printf("%d\n", ans);
  for (int i = 1; i <= ansi; i += 1) {
    printf("%d", a2[i].num);
    if (i == ansi && !ansj)
      printf("\n");
    else
      printf(" ");
  }
  for (int j = 1; j <= ansj; j += 1) {
    printf("%d", a1[j].num);
    if (j == ansj)
      printf("\n");
    else
      printf(" ");
  }
  return 0;
}
