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