/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <limits>//setprecision
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set,multiset
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
#include <numeric> //accumulate,,,
#define endl "\n";
using namespace std;

const long long INF = 4000000000000000001;
const int inf = 1001001001;
const int MOD = 1000000007;
typedef pair<long long,long long> P;

void chmax(long long &a,long long b){if(a < b) a = b;}
void chmin(long long &a,long long b){if(a > b) a = b;}

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //When end-of-a bit is 1, times simple N.
    if (M & 1) res = (res * N) % MOD;
    return res %= MOD;
}
long long gcd(long long a, long long b) {
    if (b == 0) return a; else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}



int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int N;cin >> N;
    long long W;cin >> W;
    vector<long long> w0,w1,w2,w3;
    long long standard = -1;
    for(int i = 0;i<N;i++){
        long long w,v;cin >> w >> v;
        if(i == 0) standard = w;
        if(standard + 0 == w) w0.push_back(v);
        else if(standard + 1 == w) w1.push_back(v);
        else if(standard + 2 == w) w2.push_back(v);
        else if(standard + 3 == w) w3.push_back(v);
    }
    sort(w0.begin(),w0.end(),greater<long long>());
    sort(w1.begin(),w1.end(),greater<long long>());
    sort(w2.begin(),w2.end(),greater<long long>());
    sort(w3.begin(),w3.end(),greater<long long>());
    /*vector<long long> rui0(1),rui1(1),rui2(1),rui3(1);
    for(int i = 0;i<w0.size();i++){
        rui0.push_back(rui0.at(i)+w0.at(i));
    }
    for(int i = 0;i<w0.size();i++){
        rui1.push_back(rui1.at(i)+w1.at(i));
    }
    for(int i = 0;i<w0.size();i++){
        rui2.push_back(rui2.at(i)+w2.at(i));
    }
    for(int i = 0;i<w0.size();i++){
        rui3.push_back(rui3.at(i)+w3.at(i));
    }*/
    long long ans = 0;
    long long nowV = 0,nowW = 0;
    for(long long i = 0;i<=w0.size();i++){
        
        for(long long j = 0;j<=w1.size();j++){
           

            for(long long k = 0;k<=w2.size();k++){
                

                for(long long l = 0;l<=w3.size();l++){
                    if(w0.size() != 0)for(int a = 0;a<i;a++) nowV += w0.at(a);
                    nowW += standard*(i);
                    if(w1.size() != 0)for(int a = 0;a<j;a++) nowV += w1.at(a);
                    nowW += (standard+1)*(j);
                    if(w2.size() != 0)for(int a = 0;a<k;a++) nowV += w2.at(a);
                    nowW += (standard+2)*(k);
                    if(w3.size() != 0) for(int a = 0;a<l;a++) nowV += w3.at(a);
                    nowW += (standard+3)*(l);
                    //cout << i << " " << j << " " << k << " " << l << " ";
                    //cout << nowV << " " << nowW << endl;
                    if(nowW <= W) ans = max(ans,nowV);
                    nowW = 0,nowV = 0;
                }
                
            }
        }
        
    }
    cout << ans << endl;
}


Measured memory_bytes: 3548