#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
ifstream in("rucsac.in");
ofstream out("rucsac.out");
int n, g;
in >> n >> g;
vector<int> w(n), p(n);
for (int i = 0; i < n; ++i)
in >> w[i] >> p[i];
vector<int> d(g+1, 0); // max profit for each weight using objects up to
// the last one considered
for (int i = 0; i < n; ++i) {
vector<int> d_new(g+1);
for (int ig = 0; ig <= g; ++ig) {
if (ig < w[i])
d_new[ig] = d[ig];
else
d_new[ig] = max(d[ig], d[ig-w[i]] + p[i]);
}
d.swap(d_new);
}
out << d[g] << '\n';
return 0;
}