#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int m,n;
int w[3010],d[3010];
long long int f[13000];
int main()
{
freopen("charm.in","r",stdin);
freopen("charm.out","w",stdout);
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
scanf("%d%d",&w[i],&d[i]);
for(int i=1;i<=n;i++)
for(int j=m;j>=w[i];j--)
if(f[j-w[i]]+d[i]>f[j])
f[j]=f[j-w[i]]+d[i];
printf("%lld",f[m]);
fclose(stdin);
fclose(stdout);
return 0;
}