#include <bits/stdc++.h>
#define ll long long
const int N = 105;
using namespace std;
int gi(){
  char ch=getchar(); int x=0,q=0;
  while(ch<'0' || ch>'9') (ch=='-'?q=1:0),ch=getchar();
  while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
  return q?(-x):x;
}
int w[N],v[N],s;
ll f[N][N*4],ans;
inline void dp(ll &x,ll y){
  x=x>y?x:y; return;
}
int main(){
  int n=gi(),W=gi(),m=3*n;
  memset(f,-60,sizeof(f));
  for (int i=1; i<=n; ++i)
    w[i]=gi(),v[i]=gi();
  s=w[1];
  for (int i=1; i<=n; ++i)
    w[i]-=s;
  f[0][0]=0;
  for (int k=1; k<=n; ++k)
    for (int i=n-1; i>=0; --i)
      for (int j=0; j<=m; ++j)
	dp(f[i+1][j+w[k]],f[i][j]+v[k]);
  for (int i=1; i<=n; ++i)
    for (int j=0; j<=m; ++j)
      if (1ll*s*i+j<=W)
	dp(ans,f[i][j]);
  cout<<ans;
  return 0;
}
