#include <bits/stdc++.h>
using namespace std;
const int N = 100050;
pair<int, int> a[N], b[N];
int n, v;
int cnt1, cnt2;
int ans;
int p1, p2;
int main() {
  cin >> n >> v;
  int t, p;
  for (int i = 1; i <= n; i++) {
    cin >> t >> p;
    if (t == 1)
      a[++cnt1].first = p, a[cnt1].second = i;
    else
      b[++cnt2].first = p, b[cnt2].second = i;
  }
  sort(a + 1, a + 1 + cnt1);
  reverse(a + 1, a + cnt1 + 1);
  sort(b + 1, b + 1 + cnt2);
  reverse(b + 1, b + cnt2 + 1);
  for (int i = 1; i <= cnt1; i++) a[i].first += a[i - 1].first;
  for (int i = 1; i <= cnt2; i++) b[i].first += b[i - 1].first;
  for (int i = 0; i <= min(cnt1, v); i++) {
    int m = min(cnt2, (v - i) / 2);
    if (a[i].first + b[m].first > ans) {
      ans = max(ans, a[i].first + b[m].first);
      p1 = i, p2 = m;
    }
  }
  cout << ans << endl;
  if (p1)
    for (int i = 1; i <= p1; i++) cout << a[i].second << ' ';
  if (p2)
    for (int i = 1; i <= p2; i++) cout << b[i].second << ' ';
  return 0;
}
