#include <bits/stdc++.h>
using namespace std;
long long dp;
int leen, lenn;
vector<int> q;
struct node {
  int num, wei;
} l[100050], r[100050];
;
bool com(node x, node y) { return x.num > y.num; }
int main() {
  int n, v;
  cin >> n >> v;
  memset(r, -63, sizeof(r));
  memset(l, -63, sizeof(l));
  for (int i = 1, a, b; i <= n; i++) {
    scanf("%d%d", &a, &b);
    if (a == 1) {
      l[++leen].num = b;
      l[leen].wei = i;
    } else {
      r[++lenn].num = b;
      r[lenn].wei = i;
    }
  }
  sort(l + 1, l + leen + 1, com);
  sort(r + 1, r + lenn + 1, com);
  int a = 1, b = 1;
  if (v & 1 && a <= leen) {
    q.push_back(l[a].wei);
    dp += l[a].num;
    v--;
    a++;
  }
  while (v > 1) {
    if (a > leen && b > lenn) break;
    int y = r[b].num;
    int z = 2;
    int x = l[a].num + l[a + 1].num;
    if (a + 1 > leen) {
      x = l[a].num;
      z = 1;
    }
    if (x >= y) {
      dp += x;
      for (int i = 1; i <= z; i++) q.push_back(l[a++].wei);
      v -= z;
    } else {
      dp += y;
      q.push_back(r[b].wei);
      b++;
      v -= 2;
    }
  }
  if (v && a <= leen) dp += l[a].num, q.push_back(l[a].wei);
  cout << dp << endl;
  for (vector<int>::iterator k = q.begin(); k != q.end(); ++k)
    cout << *k << " ";
  return 0;
}
