#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
const int N = 100010;
struct node {
  int t, id;
  int v;
} a[N];
int n, m;
inline bool cmp(const node &p, const node &q) {
  if (p.t != q.t)
    return p.t < q.t;
  else if (p.t == 1)
    return p.v < q.v;
  else
    return p.v > q.v;
}
int ans;
int t, v, ai;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i].t >> a[i].v, a[i].id = i;
  sort(a + 1, a + 1 + n, cmp);
  int j = 1;
  for (int i = 1; i <= n; i++) {
    t += a[i].t;
    v += a[i].v;
    while (t > m) {
      t -= a[j].t;
      v -= a[j].v;
      j++;
    }
    if (v > ans) {
      ans = v;
      ai = j;
    }
  }
  t = v = 0;
  cout << ans << '\n';
  if (ans)
    for (int i = ai; i <= n; i++) {
      t += a[i].t;
      v += a[i].v;
      if (t > m) break;
      i == ai ? cout << a[i].id : cout << ' ' << a[i].id;
    }
  return 0;
}
