#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MX = 105;
const int MM = 1000000007;

int N, W;
pii D[MX];

ll solve(int x){
	int w0 = D[1].first;
	ll T[MX][MX*3] = {};
	for(int t = 1; t <= N; t++){
		int w = D[t].first - w0, v = D[t].second;
		for(int i = x; i >= 1; i--){
			for(int j = w; j <= min(x*3ll, W-(ll)w0*x); j++){
				T[i][j] = max(T[i][j], T[i-1][j-w] + v);
			}
		}
	}
	ll mx = 0;
	for(int i = 0; i <= N*3; i++) mx = max(mx, T[x][i]);
	return mx;
}

int main()
{
	scanf("%d%d", &N, &W);
	for(int i = 1; i <= N; i++) scanf("%d%d", &D[i].first, &D[i].second);
	ll mx = 0;
	for(int i = 1; i <= N; i++){
		mx = max(mx, solve(i));
	}
	printf("%lld\n", mx);
}
