/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

//code by lynmisakura.wish to be accepted!
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

/***************************/
using namespace std;

typedef long long ll;
typedef vector<ll> vi;
typedef vector<long long> vl;
typedef pair<ll, ll> pi;
typedef vector<pair<ll, ll>> vpi;

//const long long INF = 1LL << 55;

#define itn ll
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(ll i = 0;i < n;i++)
#define rep(i,n) for(ll i = 0;i < n;i++)
#define flush fflush(stdout)
#define rrep(i,n) for(ll i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define ioboost cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20)
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, ll mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

class DSimpleKnapsack {
public:
    static constexpr int kStressIterations = 0;
    static void generateTest(std::ostream& test) {
    }

    ll N,W;
    vector<ll> val[4];
    ll X;
    vector<ll> cum[4];
    ll ans;
    int sz[4];

    void calc_cum(){
        rep(i,4)cum[i].pb(0);
        rep(i,4){
            sort(all(val[i]));
            reverse(all(val[i]));

            rep(j,val[i].size()){
                cum[i].pb(cum[i].back() + val[i][j]);
            }
        }
    }
    void input(){
        cin >> N >> W;
        for(int i = 0;i < N;i++){
            ll w,v;
            if(!i){
                cin >> w >> v;
                X = w;
                val[0].pb(v);
            }else{
                cin >> w >> v;
                val[w - X].pb(v);
            }
        }
    }
    void solve(std::istream& cin, std::ostream& cout) {
        input();
        calc_cum();
        ans = 0ll;
        rep(i,4)sz[i] = cum[i].size();
        rep(i,sz[0])rep(j,sz[1])rep(k,sz[2])rep(l,sz[3]){
                        if(j + 2*k + 3*l > W - X*(i+j+k+l))continue;
                        maxs(ans,cum[0][i]+cum[1][j]+cum[2][k]+cum[3][l]);
                    }
        cout << ans << endl;
    }
};

int main() {
	DSimpleKnapsack solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256