#include <bits/stdc++.h>
using namespace std;
const int MXN = 1e5 + 9;
struct item {
  int t, p, id;
} A[MXN], B[MXN];
int n, v, cnt1, cnt2, suma[MXN], sumb[MXN], costa[MXN], costb[MXN];
bool cmp(item a, item b) { return a.p > b.p; }
void solve() {
  sort(A + 1, A + cnt1 + 1, cmp);
  sort(B + 1, B + cnt2 + 1, cmp);
  for (int i = 1; i <= cnt1; i++) suma[i] = suma[i - 1] + A[i].p;
  for (int i = 1; i <= cnt2; i++) sumb[i] = sumb[i - 1] + B[i].p;
  int ans = 0, co = 0;
  for (int i = 0; i <= min(cnt1, v); i++) {
    int w = max(0, min(cnt2, (v - i) / 2));
    if (ans < suma[i] + sumb[w]) {
      ans = suma[i] + sumb[w];
      co = i;
    }
  }
  printf("%d\n", ans);
  for (int i = 1; i <= co; i++) {
    printf("%d ", A[i].id);
  }
  int w = min(cnt2, (v - co) / 2);
  for (int i = 1; i <= w; i++) {
    printf("%d\n", B[i].id);
  }
}
int main() {
  scanf("%d %d", &n, &v);
  int x, y;
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &x, &y);
    if (x == 1) {
      cnt1++;
      A[cnt1].id = i;
      A[cnt1].t = x, A[cnt1].p = y;
    } else {
      cnt2++;
      B[cnt2].id = i;
      B[cnt2].t = x, B[cnt2].p = y;
    }
  }
  solve();
  return 0;
}
