#include <bits/stdc++.h>

using ll = long long;
using namespace std;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;

ll dp[110][110][410] = {0};
int main(){
  int N,W;
  cin>>N>>W;
  vector<ll> w(N),v(N);
  ll kizyun;
  for(int i(0);i<N;i++){
    cin>>w[i]>>v[i];
    if(i == 0) kizyun = w[i];
    w[i] -= kizyun;
  }
  for(int i(0);i<N;i++){
    for(int j(0);j<=i;j++){
      for(int k(0);k<=3*i;k++){
        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 ans(0);
  for(int i(0);i<=N;i++){
    for(int j(0);j<=3*N;j++){
      if(kizyun*i + j <= W){
        ans = max(ans,dp[N][i][j]);
      }
    }
  }
  cout << ans << endl;
  return 0;
}

