#include <bits/stdc++.h>
using namespace std;
void zanj0() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
void solve() {
  long long int n, v;
  cin >> n >> v;
  vector<pair<long long int, long long int> > one, two;
  long long int type, cap;
  for (long long int i = 0; i < n; i++) {
    cin >> type >> cap;
    if (type == 1) {
      one.push_back({cap, i + 1});
    } else {
      two.push_back({cap, i + 1});
    }
  }
  sort(one.rbegin(), one.rend());
  sort(two.rbegin(), two.rend());
  long long int val = 0;
  long long int i;
  for (i = 0; i < one.size() && v; i++) {
    val += one[i].first;
    v--;
  }
  long long int j;
  for (j = 0; j < two.size() && v >= 2; j++) {
    val += two[j].first;
    v -= 2;
  }
  i--;
  long long int onePtr = i;
  long long int twoPtr = j - 1;
  long long int ret = 0;
  ret = val;
  while (i >= -1 && j <= two.size()) {
    if (i >= 0) {
      val -= one[i].first;
      v++;
    }
    i--;
    if (v >= 2 && j < two.size()) {
      v -= 2;
      val += two[j].first;
      if (val > ret) {
        ret = val;
        onePtr = i;
        twoPtr = j;
      }
      j++;
    }
  }
  cout << ret << "\n";
  for (long long int i = 0; i <= onePtr; i++) {
    cout << one[i].second << " ";
  }
  for (long long int i = 0; i <= twoPtr; i++) {
    cout << two[i].second << " ";
  }
  cout << "\n";
}
int32_t main() {
  zanj0();
  solve();
  cerr << "Time : " << 1000 * (long double)clock() / (long double)CLOCKS_PER_SEC
       << "ms\n";
  return 0;
}
