#include <bits/stdc++.h>
using namespace std;
int cmp(pair<int, int> a, pair<int, int> b) { return a.first > b.first; }
vector<pair<int, int> > fir, sec;
int N, V, i, a;
int main() {
  cin >> N >> V;
  for (i = 0; i < N; i++) {
    pair<int, int> t;
    cin >> a >> t.first;
    t.second = i + 1;
    if (a == 1) fir.push_back(t);
    if (a == 2) sec.push_back(t);
  }
  sort(sec.begin(), sec.end(), cmp);
  sort(fir.begin(), fir.end(), cmp);
  int x = 0, y = 0;
  vector<int> ans;
  int res = 0;
  if (V % 2 == 1 && fir.size()) {
    V--;
    x++;
    ans.push_back(fir[0].second);
    res += fir[0].first;
  }
  while (V) {
    if (x == fir.size() && y == sec.size()) break;
    int s1 = 0;
    int s2 = 0;
    if (x < fir.size()) s1 += fir[x].first;
    if (x < fir.size() - 1 && V > 1) s1 += fir[x + 1].first;
    if (y < sec.size() && V > 1) s2 += sec[y].first;
    if (!s1 && !s2) break;
    if (s1 > s2) {
      res += s1;
      if (x < fir.size() - 1 && V > 1) {
        ans.push_back(fir[x].second);
        ans.push_back(fir[x + 1].second);
        x += 2;
        V -= 2;
      } else if (x < fir.size()) {
        ans.push_back(fir[x].second);
        V--;
        x++;
      }
    } else {
      res += s2;
      ans.push_back(sec[y].second);
      V -= 2;
      y++;
    }
  }
  cout << res << endl;
  for (i = 0; i < ans.size(); i++) {
    if (i) cout << " ";
    cout << ans[i];
  }
  cout << endl;
}
