#include <bits/stdc++.h>
using namespace std;
bool comp(pair<int, int> x, pair<int, int> y) { return x.second > y.second; }
int main() {
  int n, v;
  while (~scanf("%d%d", &n, &v)) {
    vector<pair<int, int> > kays;
    vector<pair<int, int> > cats;
    vector<pair<int, int> > ans;
    int t, p;
    for (int i = 0; i < n; i++) {
      scanf("%d%d", &t, &p);
      if (t == 1)
        kays.push_back(make_pair(i + 1, p));
      else
        cats.push_back(make_pair(i + 1, p));
    }
    sort(kays.begin(), kays.end(), comp);
    sort(cats.begin(), cats.end(), comp);
    int cidx = 0;
    while (v > 1 && cidx < cats.size()) {
      ans.push_back(cats[cidx]);
      v -= 2;
      cidx++;
    }
    int lastc = ans.size() - 1;
    int kidx = 0;
    while (v > 0 && kidx < kays.size()) {
      ans.push_back(kays[kidx]);
      v -= 1;
      kidx++;
    }
    for (; kidx < kays.size() - 1 && lastc >= 0; kidx += 2) {
      if (kays[kidx].second + kays[kidx + 1].second > ans[lastc].second) {
        ans.erase(ans.begin() + lastc);
        ans.push_back(kays[kidx]);
        ans.push_back(kays[kidx + 1]);
        lastc--;
      }
    }
    if (lastc >= 0 && kidx == kays.size() - 1) {
      if (kays[kidx].second > ans[lastc].second) {
        ans.erase(ans.begin() + lastc);
        ans.push_back(kays[kidx]);
        lastc--;
      }
    }
    if (ans.size() > 0) {
      int total = 0;
      for (int i = 0; i < ans.size(); i++) total += ans[i].second;
      printf("%d\n", total);
      for (int i = 0; i < ans.size() - 1; i++) printf("%d ", ans[i].first);
      printf("%d\n", ans[ans.size() - 1].first);
    } else
      printf("0\n");
  }
  return 0;
}
