#include <bits/stdc++.h>
using namespace std;
long long vs[5][100005];
int vp[5];
long long sum1[100005], sum2[100005];
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  sum1[0] = sum2[0] = 0;
  for (int i = 1; i <= n; i++) {
    int x;
    long long y;
    cin >> x >> y;
    vs[x][++vp[x]] = y;
  }
  for (int i = 1; i <= 3; i++)
    sort(vs[i] + 1, vs[i] + 1 + vp[i], greater<int>());
  for (int i = 1; i <= vp[1]; i++) sum1[i] = sum1[i - 1] + vs[1][i];
  for (int i = 1; i <= vp[2]; i++) sum2[i] = sum2[i - 1] + vs[2][i];
  long long now = 0, ans = 0;
  for (int i = 0; i <= vp[3] && m >= 0; ++i) {
    int L = 0, R = std::min(vp[2], m / 2), M;
    while (L < R) {
      M = L + R >> 1;
      int m2 = std::min(m - M * 2, vp[1]);
      if (M * 2 + m2 < m - 1 || vs[2][M] > vs[1][m2] * 2)
        L = M + 1;
      else
        R = M;
    }
    for (int x = std::max(0, M - 50); x <= std::min(vp[2], M + 50); ++x) {
      if (x * 2 > m) continue;
      int y = std::min(vp[1], m - x * 2);
      long long a1 = now + sum1[y] + sum2[x];
      if (a1 > ans) ans = a1;
    }
    m -= 3;
    now += vs[3][i + 1];
  }
  cout << ans << endl;
  return 0;
}
