#include <bits/stdc++.h>
using namespace std;
pair<int, int> a[100005], b[100005];
int t1, t2, num[100005];
int ans, sum, maxi, maxj;
bool cmp(pair<int, int> a, pair<int, int> b) { return a.first > b.first; }
inline int read() {
  int sum = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch = '-') w = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    sum = (sum << 3) + (sum << 1) + ch - '0';
    ch = getchar();
  }
  return sum * w;
}
int main() {
  int n, v;
  n = read();
  v = read();
  for (register int i = 1; i <= n; i++) {
    int opt = read(), x = read();
    if (--opt)
      b[++t2] = make_pair(x, i);
    else
      a[++t1] = make_pair(x, i);
  }
  sort(a + 1, a + t1 + 1, cmp);
  sort(b + 1, b + t2 + 1, cmp);
  for (int i = 1; i <= t2; i++) {
    num[i] = num[i - 1] + b[i].first;
  }
  for (register int i = 0; i <= t1 && i <= v; i++) {
    int j = min((v - i) >> 1, t2);
    sum += a[i].first;
    if (sum + num[j] > ans) {
      ans = sum + num[j];
      maxi = i;
      maxj = j;
    }
  }
  cout << ans << endl;
  for (register int i = 1; i <= maxi; i++) cout << a[i].second << ' ';
  for (register int i = 1; i <= maxj; i++) cout << b[i].second << ' ';
  return 0;
}
