#include<bits/stdc++.h>
using namespace std;
int w[50000],c[50000],f[50000],N,V;
int main(){
freopen("delicious.in","r",stdin);
freopen("delicious.out","w",stdout);
cin>>N>>V;
for(int q=1;q<=N;q++)
{
cin>>w[q]>>c[q];
}
for(int i=1;i<=N;i++)
{
for(int v=V;v>=w[i];v--)
f[v]=max(f[v],f[v-w[i]]+c[i]);
}
cout<<f[V];
return 0;
}