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