#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long ll;

ll dp[110][110][330];

int main(){
    ll n,mw;cin>>n>>mw;
    ll w[111],v[111];
    rep(i,0,n)cin>>w[i]>>v[i];
    ll geta=w[0];
    rep(i,0,n)w[i]-=geta;
    
    rep(i,0,n){
        rep(j,0,i+1){
            rep(k,0,3*n+1){
                dp[i+1][j+1][k+w[i]]=max(dp[i+1][j+1][k+w[i]],dp[i][j][k]+v[i]);
                dp[i+1][j][k]=max(dp[i+1][j][k],dp[i][j][k]);
            }
        }
    }
    ll an=0;
    rep(j,0,n+1){
        rep(k,0,3*n+1){
            if(j*geta+k<=mw)an=max(an,dp[n][j][k]);
        }
    }
    cout<<an<<endl;
}

    







