#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
struct elem {
int weight, profit;
};
const int DIM = 50001;
elem v[DIM];
int curr[DIM], last[DIM];
int main() {
int n, G;
fin >> n >> G;
for (int i = 1; i <= n; i++)
fin >> v[i].weight >> v[i].profit;
for (int i = 0; i <= G; i++)
last[i] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= G; j++) {
curr[j] = last[j];
if (v[i].weight <= j)
curr[j] = max(curr[j], last[j - v[i].weight] + v[i].profit);
}
for (int j = 0; j <= G; j++)
last[j] = curr[j];
}
fout << last[G];
return 0;
}