#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  vector<int> a1{0}, a2{0};
  int n, v, t, m, mx = -1, tmp, i, p1, p2, j;
  multimap<int, int> m1, m2;
  cin >> n >> v;
  a1.reserve(n), a2.reserve(n);
  for (i = 1; i <= n; ++i) {
    cin >> t >> m;
    if (t == 1)
      a1.push_back(m), m1.insert({m, i});
    else
      a2.push_back(m), m2.insert({m, i});
  }
  sort(a1.begin() + 1, a1.end(), greater<int>());
  sort(a2.begin() + 1, a2.end(), greater<int>());
  for (i = 1; i < a1.size(); ++i) a1[i] += a1[i - 1];
  for (i = 1; i < a2.size(); ++i) a2[i] += a2[i - 1];
  i = min(v, (int)a1.size() - 1);
  while (i >= 0) {
    j = (v - i) / 2;
    j = min(j, (int)a2.size() - 1);
    tmp = a1[i] + a2[j];
    if (tmp > mx) mx = tmp, p1 = i, p2 = j;
    --i;
  }
  cout << mx << '\n';
  for (i = 1; i <= p1; ++i) {
    auto it = m1.find(a1[i] - a1[i - 1]);
    cout << it->second << " ";
    m1.erase(it);
  }
  for (i = 1; i <= p2; ++i) {
    auto it = m2.find(a2[i] - a2[i - 1]);
    cout << it->second << " ";
    m2.erase(it);
  }
}
