#include <bits/stdc++.h>
using namespace std;
int m[2], u[2];
pair<int, int> tt[2][100010];
int main() {
  int n, v;
  scanf("%d%d", &n, &v);
  for (int i = 0; i < (int)(n); ++i) {
    int t, p;
    scanf("%d%d", &t, &p);
    tt[t - 1][m[t - 1]++] = make_pair(p, i + 1);
  }
  for (int i = 0; i < (int)(2); ++i)
    sort(tt[i], tt[i] + m[i], greater<pair<int, int> >());
  u[1] = min(m[1], v / 2);
  u[0] = min(m[0], v - 2 * u[1]);
  while (u[0] + 1 < min(m[0], v) &&
         tt[1][u[1] - 1].first < tt[0][u[0]].first + tt[0][u[0]].first) {
    --u[1];
    u[0] += 2;
  }
  int c = 0;
  for (int i = 0; i < (int)(2); ++i)
    for (int j = 0; j < (int)(u[i]); ++j) c += tt[i][j].first;
  printf("%d\n", c);
  for (int i = 0; i < (int)(2); ++i)
    for (int j = 0; j < (int)(u[i]); ++j) printf("%d ", tt[i][j].second);
  return 0;
}
