#include <iostream>
#include <cstdio>
#include <cstring>
#define N 105
using namespace std;

int n, w, a0, s, mx, a[N], b[N], d[N][305];
int main()
{
	int i, j, k;
	memset(d, -1, sizeof(d));
	d[0][0] = 0;
	cin >> n >> w;
	for (i = 0; i < n; i++) {
		scanf("%d %d", &a[i], &b[i]);
		if (!i) a0 = a[0];
		a[i] -= a0;
		s += a[i];
	}
	for (i = 0; i < n; i++) {
		for (j = i + 1; j > 0; j--) {
			for (k = a[i]; k + a0 * j <= w && k <= s; k++) {
				if (d[j - 1][k - a[i]] >= 0) d[j][k] = max(d[j][k], d[j - 1][k - a[i]] + b[i]), mx = max(mx, d[j][k]);
			}
		}
	}
    cout << mx << endl;
    return 0;
}