#include <bits/stdc++.h>
using namespace std;
int c[100010], w[100010];
long long p[100010], rk[100010], dp[300010];
bool cmp(int i, int j) { return p[i] < p[j]; }
int main() {
  memset(dp, 0, sizeof(dp));
  memset(c, 0, sizeof(c));
  memset(w, 0, sizeof(w));
  memset(rk, 0, sizeof(rk));
  memset(p, 0, sizeof(p));
  int n = 0, m = 0;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d", &w[i], &c[i]);
    p[i] = (6LL * (long long)c[i]) / (long long)w[i];
    rk[i] = i;
  }
  sort(rk + 1, rk + n + 1, cmp);
  long long total = 0;
  for (int i = n; i >= 1; --i) {
    int tmpW = w[rk[i]], tmpC = c[rk[i]];
    total += tmpW;
    for (int j = total; j >= max((long long)tmpW, total - 30); --j) {
      dp[j] = max(dp[j], dp[j - tmpW] + (long long)tmpC);
    }
  }
  for (int i = 1; i <= m; ++i) {
    dp[i] = max(dp[i], dp[i - 1]);
  }
  printf("%I64d", dp[m]);
  return 0;
}
