#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
ll dp[110][110][310];
ll n, m;
pair<ll, ll> a[110];
ll func(ll here, ll ch, ll m)
{
	if (m < 0||ch<0)return -1234567890123;
	if (here == n + 1)return 0;
	ll &ret = dp[here][ch][m];
	if (ret != -1)return ret;
	ret = max(ret, func(here + 1, ch - 1, m - (a[here].first-a[1].first)) + a[here].second);
	ret = max(ret, func(here + 1, ch, m));
	return ret;
}
int main()
{
	memset(dp, -1, sizeof(dp));
	scanf("%lld %lld", &n, &m);
	ll xx = 0;
	for (int i = 1; i <= n; i++) {
		scanf("%lld %lld", &a[i].first, &a[i].second);
	}
	ll dap = 0;
	for (int i = 0; i <= m / a[1].first; i++)
	{
		dap = max(dap, func(1, m / a[1].first - i,min( m%a[1].first + a[1].first*i,(ll)300)));
	}
	printf("%lld", dap);
}