#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const double PI = 3.1415926535;
struct Boat {
  int i;
  int t;
  int p;
};
int main() {
  int n, v;
  cin >> n >> v;
  vector<Boat> bt(n);
  for (int i = 0; i < (n); ++i) {
    bt[i].i = i + 1;
    cin >> bt[i].t;
    cin >> bt[i].p;
  }
  sort(bt.begin(), bt.end(),
       [](Boat &l, Boat &r) { return l.p * r.t > r.p * l.t; });
  for (auto i = bt.begin(); i != bt.end(); ++i) {
    cerr << (*i).t << " " << (*i).p << endl;
  }
  long long sm = 0;
  int vl = 0;
  vector<int> idx;
  int last1 = -1;
  int curr = 0;
  for (; v - vl > 1 && curr < n; ++curr) {
    sm += bt[curr].p;
    vl += bt[curr].t;
    idx.push_back(bt[curr].i);
    if (bt[curr].t == 1) {
      last1 = curr;
    }
  }
  if (vl == v || curr == n) {
    cout << sm << endl;
    for (auto i = idx.begin(); i != idx.end(); ++i) {
      cout << *i << " ";
    }
    return 0;
  }
  int next2 = -1;
  int next1 = -1;
  for (; curr < n; ++curr) {
    if (bt[curr].t == 1 && next1 == -1) {
      next1 = curr;
    }
    if (bt[curr].t == 2 && next2 == -1) {
      next2 = curr;
    }
  }
  if (last1 == -1 || next2 == -1 ||
      next1 != -1 && bt[last1].p + bt[next1].p > bt[next2].p) {
    if (next1 != -1) {
      sm += bt[next1].p;
      idx.push_back(bt[next1].i);
    }
    cout << sm << endl;
    for (auto i = idx.begin(); i != idx.end(); ++i) {
      cout << *i << " ";
    }
    return 0;
  }
  if (bt[last1].p < bt[next2].p) {
    sm -= bt[last1].p;
    sm += bt[next2].p;
    idx[last1] = bt[next2].i;
  }
  cout << sm << endl;
  for (auto i = idx.begin(); i != idx.end(); ++i) {
    cout << *i << " ";
  }
  return 0;
}
