#include <bits/stdc++.h>
using namespace std;
long long n, m;
vector<long long> v[4];
vector<long long> sum[4];
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> m;
  for (long long i = 0; i < n; i++) {
    long long w, c;
    cin >> w >> c;
    v[w].push_back(c);
  }
  for (long long i = 1; i <= 3; i++)
    sort(v[i].rbegin(), v[i].rend()), sum[i].push_back(0);
  for (long long i = 1; i <= 3; i++) {
    for (long long j = 1; j <= v[i].size(); j++) {
      long long val = sum[i].back() + v[i][j - 1];
      sum[i].push_back(val);
    }
  }
  long long ans = 0;
  for (long long i = 0; i <= min(m, (long long)v[3].size()); i++) {
    long long wt = m - 3 * i;
    if (wt < 0) break;
    long long low = 0;
    long long high = min((long long)v[2].size(), wt / 2);
    while (low < high) {
      long long mid1 = low + (high - low) / 3;
      long long mid2 = high - (high - low) / 3;
      long long left1 = wt - mid1 * 2;
      long long left2 = wt - mid2 * 2;
      long long take1 = min((long long)v[1].size(), left1);
      long long take2 = min((long long)v[1].size(), left2);
      long long sum1 = sum[2][mid1] + sum[1][take1];
      long long sum2 = sum[2][mid2] + sum[1][take2];
      if (sum1 < sum2)
        low = mid1 + 1;
      else
        high = mid2 - 1;
    }
    for (long long j = max(0ll, low - 2);
         j <= min(min((long long)v[2].size(), wt / 2), low + 2); j++) {
      long long left = wt - j * 2;
      long long take = min((long long)v[1].size(), left);
      long long sum1 = sum[2][j] + sum[1][take];
      ans = max(ans, sum1 + sum[3][i]);
    }
  }
  cout << ans;
}
