#include<cstdio>
#include <fstream>
#define M 99999
using namespace std;
int m,n,i,v;
int w[M]={0},f[M]={0},d[M]={0};
int Main()
{
freopen("charm.in","r",stdin);
freopen("charm.out","w",stdout);
scanf("%d%d",&n,&m);
for(i=1;i<=n;i++)
scanf("%d%d",&w[i],&d[i]);
for(i=1;i<=n;i++)
for(v=m;v>=w[i];v--)
if(f[v-w[i]]+d[i]>f[v]) f[v]=f[v-w[i]]+d[i];
printf("%d",f[m]);
return 0;
}
int work=Main();
int main(){;
}