#include <bits/stdc++.h>
using namespace std;
const int N = 100000, M = 300000;
long long dp[M + 1][3];
vector<int> c[3];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int ci, wi;
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", &wi, &ci);
    c[wi - 1].push_back(ci);
  }
  for (int i = 0; i < 3; ++i) sort(c[i].begin(), c[i].end(), greater<int>());
  if (!c[0].empty()) {
    dp[1][0] = 1;
    dp[1][2] = c[0][0];
  }
  for (int i = 2; i <= m; ++i) {
    if (c[0].size() + c[1].size() * 2 < i) {
      dp[i][2] = max(dp[i - 1][2], dp[i - 2][2]);
      continue;
    }
    dp[i][0] = dp[i - 1][0] + 1;
    dp[i][1] = dp[i - 1][1];
    dp[i][2] =
        dp[i - 1][2] + (dp[i - 1][0] < c[0].size() ? c[0][dp[i - 1][0]] : 0);
    if (dp[i - 2][2] + (dp[i - 2][1] < c[1].size() ? c[1][dp[i - 2][1]] : 0) >
        dp[i][2]) {
      dp[i][0] = dp[i - 2][0];
      dp[i][1] = dp[i - 2][1] + 1;
      dp[i][2] =
          dp[i - 2][2] + (dp[i - 2][1] < c[1].size() ? c[1][dp[i - 2][1]] : 0);
    }
  }
  long long mx = 0;
  long long sum = 0;
  for (int i = 0; i <= c[2].size() && m - 3 * i >= 0; ++i) {
    mx = max(mx, dp[m - 3 * i][2] + sum);
    if (i != c[2].size()) sum += c[2][i];
  }
  printf("%lld\n", mx);
  return 0;
}
