#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("rucsac.in");
ofstream fout("rucsac.out");
struct obiect
{
int greutate, profit;
}v[5000];
int dp[10000]={0};
int main()
{
int n, G;
fin>>n>>G;
for(int i=0;i<n;i++)
{
fin>>v[i].greutate>>v[i].profit;
}
for(int i=0;i<n;i++)
{
for(int g=G;g>=v[i].greutate;g--)
{
if(dp[g]<dp[g-v[i].greutate]+v[i].profit)
{
dp[g]=dp[g-v[i].greutate]+v[i].profit;
}
}
}
int Pmax = 0;
for(int g=0;g<=G;g++)
{
if(dp[g]>Pmax)
Pmax=dp[g];
}
fout<<Pmax<<endl;
return 0;
}