#include <bits/stdc++.h>
using namespace std;
int acc1[100009];
int acc2[100009];
vector<pair<int, int> > v1, v2;
int n1, n2;
int main() {
  int n, v, a, b;
  scanf("%d%d", &n, &v);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &a, &b);
    if (a == 1)
      v1.push_back(make_pair(b, i + 1));
    else
      v2.push_back(make_pair(b, i + 1));
  }
  n1 = v1.size();
  n2 = v2.size();
  sort(v1.rbegin(), v1.rend());
  for (int i = 0; i < n1; i++) acc1[i + 1] = acc1[i] + v1[i].first;
  sort(v2.rbegin(), v2.rend());
  for (int i = 0; i < n2; i++) acc2[i + 1] = acc2[i] + v2[i].first;
  int ret = 0, ind = 0;
  for (int os = 0; os <= min(n1, v); os++) {
    int rem = min((v - os) / 2, n2);
    int temp = acc1[os] + acc2[rem];
    if (temp > ret) {
      ret = temp;
      ind = os;
    }
  }
  cout << ret << endl;
  int rem = min((v - ind) / 2, n2);
  string s2 = "";
  for (int i = 0; i < ind; i++) {
    cout << s2 << v1[i].second;
    s2 = " ";
  }
  for (int i = 0; i < rem; i++) {
    cout << s2 << v2[i].second;
    s2 = " ";
  }
  cout << endl;
  return 0;
}
