#include<bits/stdc++.h>
using namespace std;
int n,m,x;
int dp[105][105][305],w[105],v[105];
int dfs(int i,int j,int k)
{
	if(1LL*j*x+k>m)return -2e9;
	if(dp[i][j][k])return dp[i][j][k];
	if(i==n)return 0;
	return dp[i][j][k]=max(dfs(i+1,j,k),dfs(i+1,j+1,k+w[i+1])+v[i+1]);
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)scanf("%d%d",&w[i],&v[i]);
    x=w[1];
	for (int i=1;i<=n;i++)w[i]-=x;
	printf("%d\n",dfs(0,0,0));
	return 0;
}