#include <bits/stdc++.h>
using namespace std;
class Vehicle {
 public:
  int p, pos, t;
  Vehicle() {
    p = 0;
    pos = 0;
    t = 0;
  }
};
void merge(Vehicle arr[], int l, int m, int r) {
  int i, j, k, L = m - l + 1, R = r - m;
  Vehicle left[L], right[R];
  for (i = 0; i < L; i++) left[i] = arr[l + i];
  for (i = 0; i < R; i++) right[i] = arr[m + 1 + i];
  i = 0;
  j = 0;
  k = l;
  while (i < L && j < R) {
    if (left[i].p >= right[j].p) {
      arr[k] = left[i];
      i++;
    } else {
      arr[k] = right[j];
      j++;
    }
    k++;
  }
  while (i < L) {
    arr[k] = left[i];
    k++;
    i++;
  }
  while (j < R) {
    arr[k] = right[j];
    k++;
    j++;
  }
}
void merge_sort(Vehicle arr[], int l, int r) {
  if (l < r) {
    int m = l + (r - l) / 2;
    merge_sort(arr, l, m);
    merge_sort(arr, m + 1, r);
    merge(arr, l, m, r);
  }
}
int main() {
  Vehicle kayak[100001], catamaran[100001], first[100001], output[100001];
  int n, v, t, p, i, j, k = 0, c = 0, volume = 0, max = 0, index = 0;
  cin >> n >> v;
  srand(time(NULL));
  for (i = 1; i <= n; i++) {
    cin >> t >> p;
    if (t == 1) {
      kayak[k].p = p;
      kayak[k].pos = i;
      kayak[k].t = t;
      k++;
    } else {
      catamaran[c].p = p;
      catamaran[c].pos = i;
      catamaran[c].t = t;
      c++;
    }
  }
  if (v == 1 && kayak[0].pos == 0) {
    cout << 0;
    cout << endl;
    return 0;
  }
  merge_sort(kayak, 0, k - 1);
  merge_sort(catamaran, 0, c - 1);
  i = 0;
  j = 0;
  n = 0;
  while (volume < v) {
    if (catamaran[i].pos != 0 && volume + 2 <= v) {
      first[n] = catamaran[i];
      volume += 2;
      n++;
      i++;
    } else if (kayak[j].pos != 0) {
      first[n] = kayak[j];
      volume++;
      n++;
      j++;
    } else if (catamaran[i].pos == 0 && kayak[j].pos == 0)
      break;
  }
  n = 0;
  for (index = i - 1; index >= 0; index--)
    if (kayak[j].pos != 0 || kayak[j + 1].pos != 0) {
      if (first[index].p < kayak[j].p + kayak[j + 1].p) {
        output[n] = kayak[j];
        n++;
        j++;
        if (kayak[j].pos != 0) {
          output[n] = kayak[j];
          n++;
          j++;
        }
      } else {
        output[n] = first[index];
        n++;
      }
    } else {
      output[n] = first[index];
      n++;
    }
  while (first[i].pos != 0) {
    output[n] = first[i];
    n++;
    i++;
  }
  for (i = 0; output[i].pos != 0; i++) max += output[i].p;
  cout << max << endl;
  for (i = 0; output[i].pos != 0; i++) cout << output[i].pos << ' ';
  return 0;
}
