#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long mode(long long a) {
  a %= mod;
  if (a < 0) a += mod;
  return a;
}
long long subt(long long a, long long b) { return mode(mode(a) - mode(b)); }
long long add(long long a, long long b) { return mode(mode(a) + mode(b)); }
long long mult(long long a, long long b) { return mode(mode(a) * mode(b)); }
long long binpow(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = mult(res, a);
    a = mult(a, a);
    b >>= 1;
  }
  return res;
}
const int M = 3e5 + 7;
struct node {
  long long cost;
  long long cnt1, cnt2, cnt3;
} dp[M];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> soos[4];
  for (int i = 1; i <= n; i++) {
    int w, c;
    cin >> w >> c;
    soos[w].push_back(c);
  }
  sort(soos[1].rbegin(), soos[1].rend());
  sort(soos[2].rbegin(), soos[2].rend());
  sort(soos[3].rbegin(), soos[3].rend());
  dp[0] = {0, 0, 0, 0};
  for (int i = 1; i <= m; i++) {
    dp[i] = dp[i - 1];
    if (i >= 2 && dp[i - 2].cost > dp[i].cost) dp[i] = dp[i - 2];
    if (i >= 3 && dp[i - 3].cost > dp[i].cost) dp[i] = dp[i - 3];
    if (dp[i - 1].cnt1 < int((soos[1]).size()) &&
        dp[i - 1].cost + soos[1][dp[i - 1].cnt1] > dp[i].cost) {
      dp[i] = dp[i - 1];
      dp[i].cost += soos[1][dp[i - 1].cnt1];
      dp[i].cnt1++;
    }
    if (i >= 2 && dp[i - 2].cnt2 < int((soos[2]).size()) &&
        dp[i - 2].cost + soos[2][dp[i - 2].cnt2] > dp[i].cost) {
      dp[i] = dp[i - 2];
      dp[i].cost += soos[2][dp[i - 2].cnt2];
      dp[i].cnt2++;
    }
    if (i >= 3 && dp[i - 3].cnt3 < int((soos[3]).size()) &&
        dp[i - 3].cost + soos[3][dp[i - 3].cnt3] > dp[i].cost) {
      dp[i] = dp[i - 3];
      dp[i].cost += soos[3][dp[i - 3].cnt3];
      dp[i].cnt3++;
    }
    if (i >= 2 && dp[i - 2].cnt1 && dp[i - 2].cnt3 < int((soos[3]).size()) &&
        dp[i - 2].cost - soos[1][dp[i - 2].cnt1 - 1] + soos[3][dp[i - 2].cnt3] >
            dp[i].cost) {
      dp[i].cost = dp[i - 2].cost - soos[1][dp[i - 2].cnt1 - 1] +
                   soos[3][dp[i - 2].cnt3];
      dp[i].cnt1 = dp[i - 2].cnt1 - 1;
      dp[i].cnt2 = dp[i - 2].cnt2;
      dp[i].cnt3 = dp[i - 2].cnt3 + 1;
    }
  }
  cout << dp[m].cost;
  return 0;
}
