#include <iostream>
#include <stdio.h>
#include <cmath>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <queue>
#include <vector>
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define ll long long

using namespace std;

const int inf = 1e9 + 5;
const ll INF = 1e18 + 5;
const int maxn = 101;

ll n, a[maxn], w[maxn], s;
pair < ll, ll > dp[maxn][maxn];

int main(){
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(NULL);
	cin >> n >> s;
	for (ll i = 1; i <= n; i++){
		cin >> w[i] >> a[i];
		for (ll j = 0; j <= n; j++)
			dp[i][j] = {0, 0};
	}
	dp[1][1] = {a[1], w[1]};
	for (ll i = 2; i <= n; i++){
		for (ll j = 1; j < i; j++){
			for (ll x = 0; x < n; x++){
				if (dp[j][x].f + a[i] > dp[i][x + 1].f && dp[j][x].s + w[i] <= s)
					dp[i][x + 1] = {dp[j][x].f + a[i], dp[j][x].s + w[i]};
			}
		}
	}
	ll mx = 0;
	for (ll i = 1; i <= n; i++){
		for (ll j = 1; j <= n; j++)
			mx = max(mx, dp[i][j].f);
	}
	cout << mx;
	return 0;
}