/*
                              _,add8ba,
                            ,d888888888b,
                           d8888888888888b                        _,ad8ba,_
                          d888888888888888)                     ,d888888888b,
                          I8888888888888888 _________          ,8888888888888b
                __________`Y88888888888888P"""""""""""baaa,__ ,888888888888888,
            ,adP"""""""""""9888888888P""^                 ^""Y8888888888888888I
         ,a8"^           ,d888P"888P^                           ^"Y8888888888P'
       ,a8^            ,d8888'                                     ^Y8888888P'
      a88'           ,d8888P'                                        I88P"^
    ,d88'           d88888P'                                          "b,
   ,d88'           d888888'                                            `b,
  ,d88'           d888888I                                              `b,
  d88I           ,8888888'            ___                                `b,
 ,888'           d8888888          ,d88888b,              ____            `b,
 d888           ,8888888I         d88888888b,           ,d8888b,           `b
,8888           I8888888I        d8888888888I          ,88888888b           8,
I8888           88888888b       d88888888888'          8888888888b          8I
d8886           888888888       Y888888888P'           Y8888888888,        ,8b
88888b          I88888888b      `Y8888888^             `Y888888888I        d88,
Y88888b         `888888888b,      `""""^                `Y8888888P'       d888I
`888888b         88888888888b,                           `Y8888P^        d88888
 Y888888b       ,8888888888888ba,_          _______        `""^        ,d888888
 I8888888b,    ,888888888888888888ba,_     d88888888b               ,ad8888888I
 `888888888b,  I8888888888888888888888b,    ^"Y888P"^      ____.,ad88888888888I
  88888888888b,`888888888888888888888888b,     ""      ad888888888888888888888'
  8888888888888698888888888888888888888888b_,ad88ba,_,d88888888888888888888888
  88888888888888888888888888888888888888888b,`"""^ d8888888888888888888888888I
  8888888888888888888888888888888888888888888baaad888888888888888888888888888'
  Y8888888888888888888888888888888888888888888888888888888888888888888888888P
  I888888888888888888888888888888888888888888888P^  ^Y8888888888888888888888'
  `Y88888888888888888P88888888888888888888888888'     ^88888888888888888888I
   `Y8888888888888888 `8888888888888888888888888       8888888888888888888P'
    `Y888888888888888  `888888888888888888888888,     ,888888888888888888P'
     `Y88888888888888b  `88888888888888888888888I     I888888888888888888'
       "Y8888888888888b  `8888888888888888888888I     I88888888888888888'
         "Y88888888888P   `888888888888888888888b     d8888888888888888'
            ^""""""""^     `Y88888888888888888888,    888888888888888P'
                             "8888888888888888888b,   Y888888888888P^
                              `Y888888888888888888b   `Y8888888P"^
                                "Y8888888888888888P     `""""^
                                  `"YY88888888888P'
                                       ^""""""""'
*/
#include<bits/stdc++.h>

using namespace std;

const int maxn = 2e5 + 100;
const int mod = 1e9 + 7;
long long w[150];
long long v[150];
int a[5];
vector <int> vec[5];

long long max(long long x, long long y){return (x > y ? x : y);}
long long min(long long x, long long y){return (x < y ? x : y);}

string itos(long long x)
{
    string r;
    while(x)
    {
        int y = x % 10;
        x /= 10;
        r += char(y + '0');
    }
    reverse(r.begin(), r.end());
    return r;
}

long long divs(long long x)
{
    int r = 1;
    for (int i = 2; i * i <= x; i++)
    {
        if (x % i == 0)
        {
            if (x / i == i){r += i;}
            else{r += i; r += x / i;}
        }
    }
    return r;
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long long n, k2, p, ans = 0;
    cin >> n >> k2;
    cin >> w[0] >> v[0];
    p = w[0];
    for (int i = 1; i < n; i++){cin >> w[i] >> v[i]; w[i] -= w[0];}
    w[0] = 0;
    for (int i = 0; i < n; i++){a[w[i]]++; vec[w[i]].push_back(v[i]);}
    for (int i = 0; i < 4; i++){sort(vec[i].begin(), vec[i].end());}
    for (int i = 0; i <= a[0]; i++)
    {
        for (int j = 0; j <= a[1]; j++)
        {
            for (int k = 0; k <= a[2]; k++)
            {
                for (int l = 0; l <= a[3]; l++)
                {
                    long long tmp = p * (i + j + k + l) + j + 2 * k + 3 * l;
                    if (tmp > k2){continue;}
                    long long u = 0;
                    for (int q = vec[0].size() - 1; q >= int(vec[0].size()) - i; q--){u += vec[0][q];}
                    for (int q = vec[1].size() - 1; q >= int(vec[1].size()) - j; q--){u += vec[1][q];}
                    for (int q = vec[2].size() - 1; q >= int(vec[2].size()) - k; q--){u += vec[2][q];}
                    for (int q = vec[3].size() - 1; q >= int(vec[3].size()) - l; q--){u += vec[3][q];}
                    ans = max(ans, u);
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}








Measured memory_bytes: 256