#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 110;
ll n, s;
ll v[N], w[N];
ll dp[N][100004];
int main()
{
freopen("spestore.inp", "r", stdin);
freopen("spestore.out", "w", stdout);
cin >> n >> s;
for (ll i=1; i<=n; i++)
cin >> w[i] >> v[i];
for (ll i=0; i<=n; i++)
for (ll j=0; j<=s; j++)
{
dp[i][j] = -1e9;
}
dp[0][0] = 0;
for (ll i=1; i<=n; i++)
for (ll j=0; j<=s; j++)
{
if (j>=w[i])
{
for (ll k=0; k<i; k++)
if (v[k]<v[i])
{
dp[i][j] = max(dp[i][j], dp[k][j-w[i]]+v[i]);
}
}
}
ll res = 0;
for (ll i=1; i<=n; i++)
{
res = max(res, dp[i][s]);
}
cout << res;
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgbGwgbG9uZyBsb25nCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmNvbnN0IGludCBOID0gMTEwOwpsbCBuLCBzOwpsbCB2W05dLCB3W05dOwpsbCBkcFtOXVsxMDAwMDRdOwppbnQgbWFpbigpCnsKICAgIGZyZW9wZW4oInNwZXN0b3JlLmlucCIsICJyIiwgc3RkaW4pOwogICAgZnJlb3Blbigic3Blc3RvcmUub3V0IiwgInciLCBzdGRvdXQpOwogICAgY2luID4+IG4gPj4gczsKICAgIGZvciAobGwgaT0xOyBpPD1uOyBpKyspCiAgICAgICAgY2luID4+IHdbaV0gPj4gdltpXTsKICAgIGZvciAobGwgaT0wOyBpPD1uOyBpKyspCiAgICAgICAgZm9yIChsbCBqPTA7IGo8PXM7IGorKykKICAgICAgICB7CiAgICAgICAgICAgIGRwW2ldW2pdID0gLTFlOTsKICAgICAgICB9CiAgICBkcFswXVswXSA9IDA7CiAgICBmb3IgKGxsIGk9MTsgaTw9bjsgaSsrKQogICAgICAgZm9yIChsbCBqPTA7IGo8PXM7IGorKykKICAgICAgIHsKICAgICAgICAgICBpZiAoaj49d1tpXSkKICAgICAgICAgICB7CiAgICAgICAgICAgICAgIGZvciAobGwgaz0wOyBrPGk7IGsrKykKICAgICAgICAgICAgICAgIGlmICh2W2tdPHZbaV0pCiAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgIGRwW2ldW2pdID0gbWF4KGRwW2ldW2pdLCBkcFtrXVtqLXdbaV1dK3ZbaV0pOwogICAgICAgICAgICAgICB9CiAgICAgICAgICAgfQogICAgICAgfQogICAgbGwgcmVzID0gMDsKICAgIGZvciAobGwgaT0xOyBpPD1uOyBpKyspCiAgICB7CiAgICAgICAgcmVzID0gbWF4KHJlcywgZHBbaV1bc10pOwogICAgfQogICAgY291dCA8PCByZXM7CiAgICByZXR1cm4gMDsKfQo=