#include<bits/stdc++.h>
using namespace std;
#define ll long long
class kanp{
public:
ll weight, profit;
};
bool cmp(kanp sack1, kanp sack2)
{
return sack1.profit < sack2.profit;
}
ll traditional_kanp_sack(kanp sack[], ll primes[], ll N, ll W)
{
//dp[N][P][W]
ll ***dp = new ll**[2];
for(ll i = 0; i < 2; i++)
dp[i] = new ll*[11];
for(ll i = 0; i < 2; i++)
for(ll j = 0; j < 11; j++)
dp[i][j] = new ll[W + 1]();
ll n, p, ans1, ans2;
for(ll i = 1; i <= N; i++)
{
n = i & 1;
for(ll j = 1; j < 11; j++)
{
p = j;
for(ll w = 1; w <= W; w++)
{
//cout << n << " " << p << " " << w << "\n";
dp[n][p][w] = dp[n ^ 1][p][w];
ans1 = ans2 = INT_MIN;
if(w >= sack[i].weight)
{
ans1 = dp[n ^ 1][p][w - sack[i].weight] + sack[i].profit;
ans2 = dp[n ^ 1][p - 1][w - sack[i].weight] + (sack[i].profit * primes[p]);
}
ans1 = max(ans1, ans2);
dp[n][p][w] = max(dp[n][p][w], ans1);
}
}
}
ans1 = dp[N & 1][10][W];
for(ll i = 0; i < 2; i++)
for(ll j = 0; j < 11; j++)
delete [] dp[i][j];
for(ll i = 0; i < 2; i++)
delete [] dp[i];
delete [] dp;
return ans1;
}
int main()
{
ll t;
t = 1;
while(t--)
{
ll N, W;
cin >> N >> W;
kanp sack[N + 1];
sack[0].weight = sack[0].profit = 0;
for(ll i = 1; i <= N; i++)
cin >> sack[i].profit >> sack[i].weight;;
sort(sack, sack + N, cmp);
ll primes[11] = {1, 2, 3, 5, 7, 11, 13, 17, 19, 23, 29};
ll value = traditional_kanp_sack(sack, primes, N, W);
cout << value << "\n";
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBsbCBsb25nIGxvbmcKCmNsYXNzIGthbnB7CnB1YmxpYzoKICAgIGxsIHdlaWdodCwgcHJvZml0Owp9OwoKYm9vbCBjbXAoa2FucCBzYWNrMSwga2FucCBzYWNrMikKewogICAgcmV0dXJuIHNhY2sxLnByb2ZpdCA8IHNhY2syLnByb2ZpdDsKfQoKbGwgdHJhZGl0aW9uYWxfa2FucF9zYWNrKGthbnAgc2Fja1tdLCBsbCBwcmltZXNbXSwgbGwgTiwgbGwgVykKewogICAgICAgIC8vZHBbTl1bUF1bV10KICAgICAgICAKICAgICAgICBsbCAqKipkcCA9IG5ldyBsbCoqWzJdOwogICAgICAgIAogICAgICAgIGZvcihsbCBpID0gMDsgaSA8IDI7IGkrKykKICAgICAgICAgICBkcFtpXSA9IG5ldyBsbCpbMTFdOwogICAgICAgICAgIAogICAgICAgIGZvcihsbCBpID0gMDsgaSA8IDI7IGkrKykKICAgICAgICAgICBmb3IobGwgaiA9IDA7IGogPCAxMTsgaisrKQogICAgICAgICAgICAgIGRwW2ldW2pdID0gbmV3IGxsW1cgKyAxXSgpOwogICAgICAgICAgICAgIAogICAgICAgIGxsIG4sIHAsIGFuczEsIGFuczI7CiAgICAgICAgCiAgICAgICAgZm9yKGxsIGkgPSAxOyBpIDw9IE47IGkrKykKICAgICAgICB7CiAgICAgICAgICAgbiA9IGkgJiAxOwogICAgICAgICAgIAogICAgICAgICAgIGZvcihsbCBqID0gMTsgaiA8IDExOyBqKyspCiAgICAgICAgICAgewogICAgICAgICAgICAgICBwID0gajsKICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgIGZvcihsbCB3ID0gMTsgdyA8PSBXOyB3KyspCiAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgIC8vY291dCA8PCBuIDw8ICIgICIgPDwgcCA8PCAiICAiIDw8IHcgPDwgIlxuIjsKICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgZHBbbl1bcF1bd10gPSBkcFtuIF4gMV1bcF1bd107CiAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgIGFuczEgPSBhbnMyID0gSU5UX01JTjsKICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgaWYodyA+PSBzYWNrW2ldLndlaWdodCkKICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICBhbnMxID0gZHBbbiBeIDFdW3BdW3cgLSBzYWNrW2ldLndlaWdodF0gKyBzYWNrW2ldLnByb2ZpdDsKICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICBhbnMyID0gZHBbbiBeIDFdW3AgLSAxXVt3IC0gc2Fja1tpXS53ZWlnaHRdICsgKHNhY2tbaV0ucHJvZml0ICogcHJpbWVzW3BdKTsKICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgYW5zMSA9IG1heChhbnMxLCBhbnMyKTsKICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgZHBbbl1bcF1bd10gPSBtYXgoZHBbbl1bcF1bd10sIGFuczEpOwogICAgICAgICAgICAgICB9CiAgICAgICAgICAgfQogICAgICAgICAgICAKICAgICAgICB9CiAgICAgICAgCiAgICAgICAgYW5zMSA9IGRwW04gJiAxXVsxMF1bV107CiAgICAgICAgCiAgICAgICAgZm9yKGxsIGkgPSAwOyBpIDwgMjsgaSsrKQogICAgICAgICAgZm9yKGxsIGogPSAwOyBqIDwgMTE7IGorKykKICAgICAgICAgICAgZGVsZXRlIFtdIGRwW2ldW2pdOwogICAgICAgICAgICAKICAgICAgICBmb3IobGwgaSA9IDA7IGkgPCAyOyBpKyspCiAgICAgICAgICAgZGVsZXRlIFtdIGRwW2ldOwogICAgICAgICAgIAogICAgICAgICAgIGRlbGV0ZSBbXSBkcDsKICAgICAgICAgICAKICAgIHJldHVybiBhbnMxOyAgICAgICAKfQoKaW50IG1haW4oKQp7CiAgIGxsIHQ7CgogICB0ID0gMTsKCiAgIHdoaWxlKHQtLSkKICAgewoKICAgIGxsIE4sIFc7CgogICAgY2luID4+IE4gPj4gVzsKCiAgICBrYW5wIHNhY2tbTiArIDFdOwoKICAgIHNhY2tbMF0ud2VpZ2h0ID0gc2Fja1swXS5wcm9maXQgPSAwOwoKICAgIGZvcihsbCBpID0gMTsgaSA8PSBOOyBpKyspCiAgICAgICAgY2luID4+IHNhY2tbaV0ucHJvZml0ID4+IHNhY2tbaV0ud2VpZ2h0OzsKCiAgICBzb3J0KHNhY2ssIHNhY2sgKyBOLCBjbXApOwoKICAgIGxsIHByaW1lc1sxMV0gPSB7MSwgMiwgMywgNSwgNywgMTEsIDEzLCAxNywgMTksIDIzLCAyOX07CgogICAgbGwgdmFsdWUgPSB0cmFkaXRpb25hbF9rYW5wX3NhY2soc2FjaywgcHJpbWVzLCBOLCBXKTsKCiAgICBjb3V0IDw8IHZhbHVlIDw8ICJcbiI7CgogIH0KCiAgICByZXR1cm4gMDsKfQo=