#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 w = 1; w <= W; w++)
{
dp[n][0][w]=dp[n^1][0][w];
if(w >= sack[i].weight)
{
dp[n][0][w] = max(dp[n^1][0][w], sack[i].profit + dp[n^1][0][w- sack[i].weight]);
}
for(ll j = 1; j < 11; j++)
{
p = j;
//cout << n << " " << p << " " << w << "\n";
dp[n][p][w] = dp[n ^ 1][p][w];
ans1 = ans2 = INT_MIN;
if(w >= sack[i].weight)
{
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+1), 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;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBsbCBsb25nIGxvbmcKCmNsYXNzIGthbnB7CnB1YmxpYzoKICAgIGxsIHdlaWdodCwgcHJvZml0Owp9OwoKYm9vbCBjbXAoa2FucCBzYWNrMSwga2FucCBzYWNrMikKewogICAgcmV0dXJuIHNhY2sxLnByb2ZpdCA8IHNhY2syLnByb2ZpdDsKfQoKbGwgdHJhZGl0aW9uYWxfa2FucF9zYWNrKGthbnAgc2Fja1tdLCBsbCBwcmltZXNbXSwgbGwgTiwgbGwgVykKewogICAgICAgIC8vZHBbTl1bUF1bV10KICAgICAgICAKICAgICAgICBsbCAqKipkcCA9IG5ldyBsbCoqWzJdOwogICAgICAgIAogICAgICAgIGZvcihsbCBpID0gMDsgaSA8IDI7IGkrKykKICAgICAgICAgICBkcFtpXSA9IG5ldyBsbCpbMTFdOwogICAgICAgICAgIAogICAgICAgIGZvcihsbCBpID0gMDsgaSA8IDI7IGkrKykKICAgICAgICAgICBmb3IobGwgaiA9IDA7IGogPCAxMTsgaisrKQogICAgICAgICAgICAgIGRwW2ldW2pdID0gbmV3IGxsW1cgKyAxXSgpOwogICAgICAgICAgICAgIAogICAgICAgIGxsIG4sIHAsIGFuczEsIGFuczI7CiAgICAgICAgCiAgICAgICAgZm9yKGxsIGkgPSAxOyBpIDw9IE47IGkrKykKICAgICAgICB7CiAgICAgICAgICAgbiA9IGkgJiAxOwogICAgICAgICAgIAogICAgICAgICAgIGZvcihsbCB3ID0gMTsgdyA8PSBXOyB3KyspCiAgICAgICAgICAgCiAgICAgICAgICAgeyAgICAKICAgICAgICAgICAgICAgZHBbbl1bMF1bd109ZHBbbl4xXVswXVt3XTsKICAgICAgICAgICAgICAgaWYodyA+PSBzYWNrW2ldLndlaWdodCkKICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgICAgICBkcFtuXVswXVt3XSA9IG1heChkcFtuXjFdWzBdW3ddLCBzYWNrW2ldLnByb2ZpdCArIGRwW25eMV1bMF1bdy0gc2Fja1tpXS53ZWlnaHRdKTsKICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgIGZvcihsbCBqID0gMTsgaiA8IDExOyBqKyspCiAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgIHAgPSBqOwogICAgICAgICAgICAgICAgICAgLy9jb3V0IDw8IG4gPDwgIiAgIiA8PCBwIDw8ICIgICIgPDwgdyA8PCAiXG4iOwogICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICBkcFtuXVtwXVt3XSA9IGRwW24gXiAxXVtwXVt3XTsKICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgYW5zMSA9IGFuczIgPSBJTlRfTUlOOwogICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICBpZih3ID49IHNhY2tbaV0ud2VpZ2h0KQogICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICAgICAgIGFuczIgPSBkcFtuIF4gMV1bcCAtIDFdW3cgLSBzYWNrW2ldLndlaWdodF0gKyAoc2Fja1tpXS5wcm9maXQgKiBwcmltZXNbcF0pOwogICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICBhbnMxID0gbWF4KGFuczEsIGFuczIpOwogICAgICAgICAgICAgICAgICAgCiAgICAgICAgICAgICAgICAgICBkcFtuXVtwXVt3XSA9IG1heChkcFtuXVtwXVt3XSwgYW5zMSk7CiAgICAgICAgICAgICAgIH0KICAgICAgICAgICB9CiAgICAgICAgICAgIAogICAgICAgIH0KICAgICAgICAKICAgICAgICBhbnMxID0gZHBbTiAmIDFdWzEwXVtXXTsKICAgICAgICAKICAgICAgICBmb3IobGwgaSA9IDA7IGkgPCAyOyBpKyspCiAgICAgICAgICBmb3IobGwgaiA9IDA7IGogPCAxMTsgaisrKQogICAgICAgICAgICBkZWxldGUgW10gZHBbaV1bal07CiAgICAgICAgICAgIAogICAgICAgIGZvcihsbCBpID0gMDsgaSA8IDI7IGkrKykKICAgICAgICAgICBkZWxldGUgW10gZHBbaV07CiAgICAgICAgICAgCiAgICAgICAgICAgZGVsZXRlIFtdIGRwOwogICAgICAgICAgIAogICAgcmV0dXJuIGFuczE7ICAgICAgIAp9CgppbnQgbWFpbigpCnsKICAgbGwgdDsKCiAgIHQgPSAxOwoKICAgd2hpbGUodC0tKQogICB7CgogICAgbGwgTiwgVzsKCiAgICBjaW4gPj4gTiA+PiBXOwoKICAgIGthbnAgc2Fja1tOICsgMV07CgogICAgc2Fja1swXS53ZWlnaHQgPSBzYWNrWzBdLnByb2ZpdCA9IDA7CgogICAgZm9yKGxsIGkgPSAxOyBpIDw9IE47IGkrKykKICAgICAgICBjaW4gPj4gc2Fja1tpXS5wcm9maXQgPj4gc2Fja1tpXS53ZWlnaHQ7OwoKICAgIHNvcnQoc2Fjaywgc2FjayArIChOKzEpLCBjbXApOwoKICAgIGxsIHByaW1lc1sxMV0gPSB7MSwgMiwgMywgNSwgNywgMTEsIDEzLCAxNywgMTksIDIzLCAyOX07CgogICAgbGwgdmFsdWUgPSB0cmFkaXRpb25hbF9rYW5wX3NhY2soc2FjaywgcHJpbWVzLCBOLCBXKTsKCiAgICBjb3V0IDw8IHZhbHVlIDw8ICJcbiI7CgogIH0KCiAgICByZXR1cm4gMDsKfQo=