#include <bits/stdc++.h>
int t[110000], p[110000], a[110000];
bool cmp(int a, int b) { return 2 * p[a] / t[a] > 2 * p[b] / t[b]; }
int main() {
  using std::cin;
  using std::cout;
  int N;
  int V;
  cin >> N >> V;
  for (int i = 0; i < N; ++i) {
    cin >> t[i] >> p[i];
    a[i] = i;
  }
  std::sort(a, a + N, cmp);
  int ost = V;
  int lastw = -1;
  int ans = 0;
  std::vector<int> res;
  for (int i = 0; i < N; ++i) {
    if (ost >= t[a[i]]) {
      ost -= t[a[i]];
      ans += p[a[i]];
      if (t[a[i]] == 1) lastw = a[i];
      res.push_back(a[i]);
    } else {
      if (ost == 1 && lastw != -1 && p[lastw] < p[a[i]]) {
        ost = 0;
        ans += p[a[i]];
        ans -= p[lastw];
        res.push_back(a[i]);
        res.erase(std::find(res.begin(), res.end(), lastw));
      }
      break;
    }
  }
  cout << ans << std::endl;
  for (int i = 0; i < res.size(); ++i) cout << res[i] + 1 << " ";
  return 0;
}
