#include <cstdio>
using namespace std;
int main()
{
freopen("charm.in","r",stdin);
freopen("charm.out","w",stdout);
int i,j,n,maxm,temp,wei[3402],val[3402],f[12881]={0};
scanf("%d %d\n",&n,&maxm);
for (i=0;i<n;i++)
scanf("%d %d",&wei[i],&val[i]);
for (i=0;i<n-1;i++)
for (j=maxm;j>=wei[i];j--)
{
temp=val[i]+f[j-wei[i]];
if (temp>f[j])
f[j]=temp;
}
temp=val[i]+f[maxm-wei[i]];
if (temp>f[maxm])
f[maxm]=temp;
printf("%d\n",f[maxm]);
return(0);
}