#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int m,n;
int wei[3410],jia[3410];
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",&wei[i],&jia[i]);
for(int i=1;i<=n;i++)
for(int j=m;j>=wei[i];j--)
if(f[j-wei[i]]+jia[i]>f[j])
f[j]=f[j-wei[i]]+jia[i];
printf("%lld",f[m]);
fclose(stdin);
fclose(stdout);
return 0;
}