#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T sqr(T x) {
  return x * x;
}
const double pi = acos(-1.0), eps = 1e-9, e = exp(1.0);
const int INF = 1000 * 1000 * 1000 + 7, MAXN = 100005, MOD = 1000000007,
          MAXBIT = 30, pHash = 53;
const long long INFL = 1e+18;
void prepare(string s) {
  if ((int)s.size() != 0) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
  }
}
struct Superstring {
  string s;
  long long h1[MAXN], h2[MAXN];
  long long pp1[MAXN], pp2[MAXN];
  void read() {
    cin >> s;
    s.insert(s.begin(), ' ');
    countHashes();
  }
  void countHashes() {
    int n = (int)s.size();
    pp1[0] = 1;
    pp2[0] = 1;
    for (int i = 1; i <= n; i++) {
      pp1[i] = pp1[i - 1] * pHash;
      pp2[i] = (pp2[i - 1] * pHash) % MOD;
    }
    h1[0] = s[0] - 'a' + 1;
    h2[0] = (s[0] - 'a' + 1) % MOD;
    for (int i = 1; i < n; i++) {
      h1[i] = h1[i - 1] + pp1[i] * (s[i] - 'a' + 1);
      h2[i] = (h2[i - 1] + pp2[i] * (s[i] - 'a' + 1)) % MOD;
    }
  }
  long long getHash1(int l, int r) {
    long long h = h1[r];
    if (l > 0) h -= h1[l - 1];
    h *= pp1[(int)s.size() - 1 - r];
    return h;
  }
  long long getHash2(int l, int r) {
    long long h = h2[r];
    if (l > 0) h = (h - h2[l - 1] + MOD) % MOD;
    h = (h * pp2[(int)s.size() - 1 - r]) % MOD;
    return h;
  }
};
int n, v, numa, numb;
vector<pair<int, int> > a, b;
long long A[MAXN], B[MAXN], ans;
int binSearch(long long x) {
  int l = -1, r = (int)b.size() + 1;
  while (r - l > 1) {
    int mid = (l + r) / 2;
    if (2 * mid <= v - x) {
      l = mid;
    } else {
      r = mid;
    }
  }
  return l;
}
void solve() {
  cin >> n >> v;
  for (int i = 0; i < n; ++i) {
    int p, q;
    cin >> p >> q;
    if (p == 1)
      a.push_back(make_pair(q, i + 1));
    else
      b.push_back(make_pair(q, i + 1));
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());
  reverse(a.begin(), a.end());
  reverse(b.begin(), b.end());
  for (int i = 1; i <= (int)a.size(); i++) {
    A[i] = A[i - 1] + a[i - 1].first;
  }
  for (int i = 1; i <= (int)b.size(); i++) {
    B[i] = B[i - 1] + b[i - 1].first;
  }
  for (int i = 0; i <= (int)a.size(); i++) {
    if (i > v) break;
    int j = binSearch(i);
    if (A[i] + B[j] > ans) {
      ans = A[i] + B[j];
      numa = i;
      numb = j;
    }
  }
  cout << ans << endl;
  for (int i = 0; i < numa; ++i) cout << a[i].second << ' ';
  for (int i = 0; i < numb; ++i) cout << b[i].second << ' ';
}
int main() {
  prepare("");
  solve();
  return 0;
}
