#include<iostream>
#include<cstdio>
#define syy myson
using namespace std;
typedef long long LL;
const int maxn=3500;
LL n,m,w[maxn],d[maxn],f[13000],i;
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(int 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 main(){;};
int syy=Main();