#include<bits/stdc++.h>
#include<unordered_map>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define endl                         '\n'	
#define Ceil(x,y)             ((x+y-1)/y)
#define sz(s)               (int)s.size()
#define RT(x)           return cout<<x,0;
#define mem(x,y)    memset(x,y,sizeof(x))
#define all(v) ((v).begin()), ((v).end())
#define vi                    vector<int>
#define pii                 pair<int,int>
#define watch(x) cout<<(#x)<<" = "<<x<<endl
#define forr(i, n) for (int i = 0; i < int(n); i++)
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
const double PI = acos(-1), EPS = 1e-7;
const int OO = 0x3f3f3f3f, N = 1e7 + 5, mod = 1e9 + 7;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll x, ll y) { return (!y) ? x : gcd(y, x%y); }
ll lcm(ll x, ll y) { return ((x / gcd(x, y))*y); }
void mansour()
{
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt" , "r" , stdin) ;
    freopen("output.txt" , "w" , stdout) ;
#endif
}
ll n,x,mx;
vector<pair<ll,ll>>v;
ll dp[102][100005];
ll knap(ll i, ll x)
{
	if(i==n || x<=0)
		return 0;
	ll ch1=0;
	if(dp[i+1][x]!=-1)
		ch1=dp[i+1][x];
	else
		ch1=knap(i+1,x);
	ll ch2=0;
	if(v[i].first<=x)
	{
		if(dp[i+1][x-v[i].first]!=-1)
			ch2=dp[i+1][x-v[i].first];
		else
			ch2=knap(i+1,x-v[i].first)+v[i].second;
	}
	return dp[i][x]=max(ch1,ch2);
}
int main()
{
	mansour();
	//file();
	/*The First*/
	memset(dp,-1,sizeof(dp));
	ll a,b;
	cin>>n>>x;
	for(int i=0;i<n;i++)
	{
		cin>>a>>b;
		v.push_back(make_pair(a,b));
	}
	cout <<knap(0,x)<<"\n";
}