#include <bits/stdc++.h>

using namespace std;

#define el				'\n'
#define sz(v)			((int)((v).size()))
#define all(v)          ((v).begin()),((v).end())
#define clr(v, d)		memset(v, d, sizeof(v))

double const EPS = 1e-8, PI = acos(-1);
const int N = 100 + 9, M = 1e5 + 9, OO = (int) 1e6 + 1;
const long long MOD = 1e9 + 7;

typedef long long ll;

void INPUT() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
	cout << fixed << setprecision(0);
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
}

ll n, W, weights[N], values[N];
map<pair<int, ll>, ll> mem;

ll dp(int i, ll w) {
	if (w < 0)
		return -OO;
	if (i == n)
		return 0;
	ll ret = mem[ { i, w }];
	if (ret)
		return ret;
	ll a = dp(i + 1, w);
	ll b = dp(i + 1, w - weights[i]) + values[i];
	ret = max(a, b);
	mem[ { i, w }] = ret;
	return ret;
}

int main() {
	INPUT();
	cin >> n >> W;
	for (int i = 0; i < n; ++i) {
		cin >> weights[i] >> values[i];
	}
	cout << dp(0, W);

	return 0;

}
