/*
    author: Salam_35
    problem name: The Knapsack Problem
*/

#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define pb push_back
#define sc(n) scanf("%d",&n)
#define Max 100005
#define scan(n) scanf("%lld",&n)
#define pi acos(-1.0)
#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ALL(x) x.begin(),x.end()
#define pii pair<int,int>
#define load(array,size)  for(int i=0 ; i<size ; i++) cin>>array[i] ;
#define load1(array,size)  for(int i=1 ; i<=size ; i++) cin>>array[i] ;
#define INF	1LL<<19
#define pll pair<ll,ll>

ll s,n;
ll price[2005],weight[2005];

ll dp[150][100050];

ll solve(ll i, ll w)
{
    int profit1=0,profit2=0;
    if(i==(n+1))
        return 0;

    if(dp[i][w]!=-1) return dp[i][w];
    if(w+weight[i]<=s)
       return dp[i][w] =max( solve(i+1,w), price[i]+solve(i+1,w+weight[i]));
    else
        return dp[i][w]=solve(i+1,w);
}

int main()
{
    memset(dp, -1, sizeof dp);
    cin >> n >> s;
    for(ll i=0;i<n;i++)
    {
        ll a,b;
        cin >> weight[i] >> price[i];
    }
    cout<<solve(0,0)<<endl;
}
