#include <bits/stdc++.h>
using namespace std;
int n;
long long v;
vector<pair<long long, int> > kk, kt;
vector<int> ans;
long long ans_sum = 0;
bool cmp(const pair<long long, int> &a, const pair<long long, int> &b) {
  return a.first > b.first;
}
void solve() {
  sort(kk.begin(), kk.end(), cmp);
  sort(kt.begin(), kt.end(), cmp);
  int i = 0, j = 0;
  for (; i < int(kk.size()) && j < int(kt.size()) && v > 0;) {
    if (kk[i].first * 2 >= kt[j].first) {
      v--;
      ans_sum += kk[i].first;
      ans.push_back(kk[i].second);
      i++;
    } else {
      v -= 2;
      if (v == -1) {
        v = 1;
        break;
      }
      ans_sum += kt[j].first;
      ans.push_back(kt[j].second);
      j++;
    }
  }
  if (v > 1) {
    for (; i < int(kk.size()) && v > 0; ++i) {
      v--;
      ans_sum += kk[i].first;
      ans.push_back(kk[i].second);
    }
    for (; j < int(kt.size()) && v > 1; ++j) {
      v -= 2;
      ans_sum += kt[j].first;
      ans.push_back(kt[j].second);
    }
  }
  if (v != 1) {
    return;
  }
  if (j == int(kt.size()) && v) {
    for (; i < int(kk.size()) && v > 0; ++i) {
      v--;
      ans_sum += kk[i].first;
      ans.push_back(kk[i].second);
    }
  }
  if (!i || j == int(kt.size())) {
    return;
  }
  if (i == int(kk.size())) {
    i--;
    if (kk[i].first <= kt[j].first) {
      ans_sum -= kk[i].first;
      ans_sum += kt[j].first;
      for (int k = 0; k < int(ans.size()); ++k) {
        if (ans[k] == kk[i].second) {
          ans.erase(ans.begin() + k);
          ans.push_back(kt[j].second);
          break;
        }
      }
    }
    return;
  }
  if (kk[i].first + kk[i - 1].first <= kt[j].first) {
    ans_sum -= kk[i - 1].first;
    ans_sum += kt[j].first;
    for (int k = 0; k < int(ans.size()); ++k) {
      if (ans[k] == kk[i - 1].second) {
        ans.erase(ans.begin() + k);
        ans.push_back(kt[j].second);
        break;
      }
    }
  } else {
    ans_sum += kk[i].first;
    ans.push_back(kk[i].second);
  }
  return;
}
int main(int argc, char *argv[]) {
  scanf("%d%lld", &n, &v);
  for (int i = 0; i < n; ++i) {
    int t;
    long long p;
    scanf("%d%lld", &t, &p);
    (t == 1) ? kk.push_back(make_pair(p, i + 1))
             : kt.push_back(make_pair(p, i + 1));
  }
  solve();
  printf("%lld\n", ans_sum);
  for (int i = 0; i < int(ans.size()); ++i) {
    printf("%d ", ans[i]);
  }
  return 0;
}
