#include <bits/stdc++.h>
using namespace std;
int N, C;
vector<int> Adj[4];
vector<int> v2;
int n1, n2, n3;
long long s[4][100005];
long long ans1, ans2;
bool cmp(const int& a, const int& b) { return a > b; }
void calS(int k) {
  sort(Adj[k].begin(), Adj[k].end(), cmp);
  for (int i = 0; i < Adj[k].size(); i++) {
    s[k][i + 1] = s[k][i] + Adj[k][i];
  }
  return;
}
long long solve(int n2) {
  n1 = C - 3 * n3 - 2 * n2;
  if (n1 < 0) return 0;
  n1 = max(n1, 0);
  n1 = min(n1, int(Adj[1].size()));
  return s[2][n2] + s[1][n1];
}
long long work(int C) {
  int l = 0, r = min(C / 2, int(Adj[2].size())) - 1;
  if (r <= 0) {
    return max(solve(0), solve(1));
  }
  int mid;
  while (r - l > 5) {
    mid = (r + l) / 2;
    if (solve(mid + 1) > solve(mid))
      l = mid;
    else
      r = mid;
  }
  for (mid = l; mid <= r; mid++) {
    if (solve(mid + 1) < solve(mid)) return solve(mid);
  }
  return solve(r + 1);
}
int main() {
  cin >> N >> C;
  int w, v;
  for (int i = 1; i <= N; i++) {
    cin >> w >> v;
    Adj[w].push_back(v);
  }
  for (int k = 1; k <= 3; k++) calS(k);
  long long ans = 0;
  for (n3 = 0; 3 * n3 <= C && n3 <= Adj[3].size(); n3++) {
    ans = max(ans, s[3][n3] + work(C - 3 * n3));
  }
  cout << ans;
  return 0;
}
