#include <bits/stdc++.h>

using namespace std;

#define rep(i,m,n) for(int i=m;i<n;i++)


int main(){
 long n,w;
  cin >>n >> w;
  vector<vector<long>> v(4);
  long w1,b;
   cin >> w1 >> b;
   v[0].push_back(b);
  rep(i,1,n){
   long a;
    cin >> a >> b;
    v[a-w1].push_back(b);
  }
  
   rep(i,0,4) {
     v[i].push_back(1000000000);
     sort(v[i].begin(),v[i].end(),greater<long>());
     v[i][0]=0;
     rep(j,1,v[i].size()) v[i][j]+=v[i][j-1];
   }
  
   long res=0;
   rep(i,0,v[0].size()){
     rep(j,0,v[1].size()){
     rep(k,0,v[2].size()){
      rep(l,0,v[3].size()){
            long weight=w1*i+(w1+1)*j+(w1+2)*k+(w1+3)*l;
        if(weight>w) break;
        long value=v[0][i]+v[1][j]+v[2][k]+v[3][l];
        res=max(res,value);
      }
     }
    }
   }
  cout << res << endl;
  
 
}