#include <vector> 
#include <list> 
 #include <map>
 #include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << '=' << (x) << endl;
#define debug(x) cerr << #x << '=' << (x) << '('<<'L' << __LINE__ << ')' << ' ' << __FILE__ << endl;

const LL MAX_N=123,MAX_W=1234567890;


// LL dp[MAX_N][MAX_W];//N個までの商品を用いてW以内の重さでできる最大の価値
// LL v[MAX_N],w[MAX_N];

// LL N,W;
// int main(){
   
//     CLR(dp);

//     cin>>N>>W;
//     FOR(i,1,N+1){
//         cin>>w[i];
//         cin>>v[i];
//     }

//     FOR(i,1,N+1) FOR(j,1,W+1){
//         if(j<w[i]){
//             dp[i][j]=dp[i-1][j];
//         }
//         else{
//             dp[i][j]=max(dp[i-1][j-w[i]]+v[i],dp[i-1][j]);
//         }
//     }

//     cout<<dp[N][W]<<endl;



// }

LL N,W,Wmin;

vector< vector<LL> > V;
LL w,v;
int main(){
    V=vector< vector<LL> >(4,vector<LL>(1,0));
    
    cin>>N>>W;

    cin>>Wmin>>v;

    V[0].push_back(v);
    FOR(i,1,N){
        cin>>w>>v;
        V[w-Wmin].push_back(v);
        //numW[w-Wmin]++;
    }
    
    
    REP(i,4)sort((V[i]).begin()+1,(V[i]).end(),std::greater<LL>());

    cerr<<endl;
    REP(i,4){REP(j,V[i].size()){cerr<<V[i][j]<<" ";} cerr<<endl;}
    cerr<<endl;

    REP(i,4){
        FOR(j,1,V[i].size()){
            V[i][j]+=V[i][j-1];
        }
    }

    cerr<<endl;
    REP(i,4){REP(j,V[i].size()){cerr<<V[i][j]<<" ";} cerr<<endl;}
    
    cerr<<endl;

    LL sum=0,maxsum=0;

    REP(i,V[0].size())REP(j,V[1].size())REP(k,V[2].size())REP(l,V[3].size()) {
        if(i*Wmin+j*(Wmin+1)+k*(Wmin+2)+l*(Wmin+3)>W){continue;}
        sum=V[0][i]+V[1][j]+V[2][k]+V[3][l];
        cerr<<i<<j<<k<<l<<" "<<sum<<endl;                
        maxsum=max(sum,maxsum);


    }
    cout<<maxsum<<endl;
}




Measured memory_bytes: 256