#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define mod 1000000007
ll gcd (ll a, ll b) {return ( a ? gcd(b%a, a) : b );}
ll modPow(ll x,ll n,ll MOD){ll res=1;while(n>0){if(n%2 == 1){res=(res*x)%MOD;}n/=2;x=(x*x)%MOD;}return res;}
ll modInverse(ll a,ll p){return modPow(a,p-2,p);}
void solve(ll wt[],ll val[],ll n,ll W)
{
int i, j;
ll K[n+1][W+1];
for (i = 0; i <= n; i++)
{
for (j = 0; j <= W; j++)
{
if (i==0 || j==0)
K[i][j] = 0;
else if (j-wt[i-1]>=0)
K[ i ][ j ] = max(val[i-1] + K[i-1][j-wt[i-1]], K[i-1][j]);
else
K[ i ][ j ] = K[i-1][ j ];
}
}
cout<< K[n][W];
}
int main()
{
ios_base::sync_with_stdio (false);
ll n,m,i,j,k;
cin>>n>>m;
ll wt[n],cost[n];
for(i=0;i<n;i++)
cin>>wt[i]>>cost[i];
solve(wt,cost,n,m);
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7IAp0eXBlZGVmIGxvbmcgbG9uZyBpbnQgbGw7CiNkZWZpbmUgbW9kIDEwMDAwMDAwMDcKbGwgZ2NkIChsbCBhLCBsbCBiKSB7cmV0dXJuICggYSA/IGdjZChiJWEsIGEpIDogYiApO30KbGwgbW9kUG93KGxsIHgsbGwgbixsbCBNT0Qpe2xsIHJlcz0xO3doaWxlKG4+MCl7aWYobiUyID09IDEpe3Jlcz0ocmVzKngpJU1PRDt9bi89Mjt4PSh4KngpJU1PRDt9cmV0dXJuIHJlczt9CmxsIG1vZEludmVyc2UobGwgYSxsbCBwKXtyZXR1cm4gbW9kUG93KGEscC0yLHApO30KCnZvaWQgc29sdmUobGwgd3RbXSxsbCB2YWxbXSxsbCBuLGxsIFcpCnsKICAgIGludCBpLCBqOwogICBsbCBLW24rMV1bVysxXTsKIAogICBmb3IgKGkgPSAwOyBpIDw9IG47IGkrKykKICAgewogICAgICAgZm9yIChqID0gMDsgaiA8PSBXOyBqKyspCiAgICAgICB7CiAgICAgICAgICAgaWYgKGk9PTAgfHwgaj09MCkKICAgICAgICAgICAgICAgS1tpXVtqXSA9IDA7CiAgICAgICAgICAgZWxzZSBpZiAoai13dFtpLTFdPj0wKQogICAgICAgICAgICAgICAgIEtbIGkgXVsgaiBdID0gbWF4KHZhbFtpLTFdICsgS1tpLTFdW2otd3RbaS0xXV0sICBLW2ktMV1bal0pOwogICAgICAgICAgIGVsc2UKICAgICAgICAgICAgICAgICBLWyBpIF1bIGogXSA9IEtbaS0xXVsgaiBdOwogICAgICAgfQogICB9CiBjb3V0PDwgS1tuXVtXXTsKCn0KCgppbnQgbWFpbigpCnsKICAgICAKICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyAoZmFsc2UpOwogICBsbCBuLG0saSxqLGs7CiAgIGNpbj4+bj4+bTsKICAgbGwgd3Rbbl0sY29zdFtuXTsKICAgCiAgIGZvcihpPTA7aTxuO2krKykKICAgY2luPj53dFtpXT4+Y29zdFtpXTsKICAgCiAgIHNvbHZlKHd0LGNvc3QsbixtKTsKICAgICAgCn0=