#include<cstdio>
#include<algorithm>
#define MN 101
using namespace std;
int n,m,w1,w,v[4][MN];
long long mmh=0,q[4][MN];
bool cmp(int a,int b){return a>b;}
int main(){
	register int i;
	scanf("%d%d",&n,&m);scanf("%d",&w1);
	v[0][0]=1;scanf("%d",&v[0][1]);
	for (i=1;i<n;i++){
		scanf("%d",&w);
		scanf("%d",&v[w-w1][++v[w-w1][0]]);
	}
	sort(v[0]+1,v[0]+v[0][0]+1,cmp);
	sort(v[1]+1,v[1]+v[1][0]+1,cmp);
	sort(v[2]+1,v[2]+v[2][0]+1,cmp);
	sort(v[3]+1,v[3]+v[3][0]+1,cmp);
	for (i=0;i<4;i++)
	for (int j=1;j<=v[i][0];j++) q[i][j]=q[i][j-1]+v[i][j];
	for (int i=0;i<=v[0][0];i++)
	for (int j=0;j<=v[1][0];j++)
	for (int k=0;k<=v[2][0];k++)
	for (int l=0;l<=v[3][0];l++)
	if (1LL*i*w1+1LL*j*(w1+1)+1LL*k*(w1+2)+1LL*l*(w1+3)<=m)
	if (q[0][i]+q[1][j]+q[2][k]+q[3][l]>mmh) mmh=q[0][i]+q[1][j]+q[2][k]+q[3][l];
	printf("%lld",mmh);
}