#include<stdio.h>
#include<string.h>
int N,W,dp[100][10005],v[105],w[105],i,j,k;

int dfs(int d,int nw)
{
	int r1,r2;
	if(dp[d][nw]!=-1)return dp[d][nw];
	if(d==N)return 0;
	if(w[j]>W)
		return dp[d][nw]=dfs(d+1,nw);

	r1=dfs(d+1,nw);
	r2=dfs(d+1,nw-w[d])+v[d];
	return dp[d][nw]=r1>r2?r1:r2;
}

int main()
{
	memset(dp,-1,sizeof(dp));
	scanf("%d%d",&N,&W);
	for(i=0;i<N;i++)scanf("%d%d",&v[i],&w[i]);
	printf("%d\n",dfs(0,W));
	return 0;
}