


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#define LL long long 
using namespace std;

LL dp[105][315];
LL w[105],v[105];
 
int main(){
    LL n,W;
    scanf("%lld%lld",&n,&W);
    LL sum=0;
    scanf("%lld%lld",&w[1],&v[1]);
    for(int i=2;i<=n;i++)
    {
    	scanf("%lld%lld",&w[i],&v[i]);
    	w[i]-=(w[1]-1);
    	sum+=w[i];
	}
	sum+=1; 
	LL ww=w[1]-1;
	w[1]=1;
	LL ans=0;
 
    for(LL i=1;i<=n;i++)
	{
        for(LL j=i;j>=1;j--)
		{
            for (LL k=sum;k>=w[i];k--)
			{
                dp[j][k]=max(dp[j][k],dp[j-1][k-w[i]]+v[i]);
                if(j*ww+k<=W) 
				{
					ans=max(dp[j][k],ans);
				}
            }
        }
    }
 	printf("%lld\n",ans);
    return 0;
}