#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const int mod = 1e9 + 7;
long long kek[100005], w[100005], dp[1337228], c[100005], nm[100005];
bool kekekekekekkek(int i, int j) { return kek[i] > kek[j]; }
int main() {
  ios_base::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> w[i] >> c[i];
    kek[i] = 1337 * c[i] / w[i];
    nm[i] = i;
  }
  sort(nm + 1, nm + n + 1, kekekekekekkek);
  int cur = 0;
  for (int i = 1; i <= n; i++) {
    int curw = w[nm[i]], curc = c[nm[i]];
    cur += curw;
    for (int j = cur; j >= max(curw, cur - 228); j--) {
      dp[j] = max(dp[j], dp[j - curw] + curc);
    }
  }
  for (int i = 1; i <= m; i++) {
    dp[i] = max(dp[i], dp[i - 1]);
  }
  cout << dp[m] << endl;
}
