#include <bits/stdc++.h>
using namespace std;
pair<int, int> a[100010], b[100010];
int ps[100010];
int main() {
  int n, v;
  scanf("%d%d", &n, &v);
  int x = 0, y = 0;
  for (int i = 0; i < n; i++) {
    int t, p;
    scanf("%d%d", &t, &p);
    if (t & 1)
      a[x++] = {p, i + 1};
    else
      b[y++] = {p, i + 1};
  }
  sort(a, a + x);
  reverse(a, a + x);
  sort(b, b + y);
  reverse(b, b + y);
  for (int i = 0; i < x; i++) {
    ps[i] = a[i].first;
    if (i) ps[i] += ps[i - 1];
  }
  vector<int> anw;
  int a1 = 0;
  int a2 = 0;
  int r = -1;
  int g = 0;
  for (int i = -1; i < y; i++) {
    if (i >= 0) {
      v -= 2;
      g += b[i].first;
    }
    if (v < 0) break;
    int c = g;
    int u = -1;
    if (v != 0 && x) {
      u = min(x - 1, v - 1);
      c += ps[u];
    }
    if (r < c) {
      r = c;
      a1 = u + 1;
      a2 = i + 1;
    }
  }
  for (int i = 0; i < a1; i++) anw.push_back(a[i].second);
  for (int i = 0; i < a2; i++) anw.push_back(b[i].second);
  printf("%d\n", r);
  for (int i = 0; i < int(anw.size()); i++) {
    if (i != 0) printf(" ");
    printf("%d", anw[i]);
  }
  printf("\n");
}
