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


#define endl            '\n'
#define ll              long long
#define ld              long double 
#define ull             unsigned long long int
#define MOD             (ll)(1e9 + 7)
#define vi              vector<int>
#define vl              vector<long>
#define vll             vector<ll>
#define vs              vector<string>
#define pll             pair<ll,ll>
#define mll             map<ll,ll>
#define len(x)          x.length()
#define all(x)          x.begin(),x.end()
#define deb1(x)         cout<<#x<<" "<<x<<endl;
#define deb2(x,y)       cout<<#x<<" "<<x<<'	'<<#y<<" "<<y<<endl;
#define deb3(x,y,z)     cout<<#x<<" "<<x<<'	'<<#y<<" "<<y<<'	'<<#z<<" "<<z<<endl;
#define debug1(x)       cerr<<#x<<" "<<x<<endl;
#define debug2(x,y)     cerr<<#x<<" "<<x<<'	'<<#y<<" "<<y<<endl;
#define debug3(x,y,z)   cerr<<#x<<" "<<x<<'	'<<#y<<" "<<y<<'	'<<#z<<" "<<z<<endl;
#define info(s)         cerr<<s<<" "<<endl;
#define fr(a,b,c)       for(auto a=b;b<c?a<c:a>c;b<c?a++:a--)
#define frc(a,b,c)      for(auto a=b;a!=c;a++)
#define tr(it, a)       for(auto it = a.begin(); it != a.end(); it++)
#define lb(v,x)         lower_bound(v.begin(), v.end(), x)
#define ub(v,x)         upper_bound(v.begin(), v.end(), x)
#define clr(x)          memset(x, 0, sizeof(x))
#define GR              (double)(1 + sqrt(5)) / 2
#define fib(n)          (ll)round(pow(GR,n) / sqrt(5))
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define out1(x)         cout<<x<<" "<<endl
#define out2(x,y)       cout<<x<<" "<<y<<endl
#define SORT(a)         sort(all(a));
#define SORTR(a)        sort(all(a),greater<ll>());
#define ARRAY(a,n)      vll a; fr(i,0,n) { ll temp; cin>>temp; a.pb(temp); }  
#define PRINT(a)        for(auto x:a)cout<<x<<" ";cout<<endl
#define MAX             100050
#define pb              push_back
#define mp              make_pair
#define F               first
#define S               second


template<typename T>
ostream& operator<<(ostream &out,const vector<T> &v);


template<typename T>
istream& operator>>(istream &in,vector<T> &v);


ll dp[100005][105];


ll knapsack(vll &val,vll &wt,int w,int n){
    if(n==0||w==0)
        return 0;
    if(dp[w][n]!=-1)
        return dp[w][n];
    if(wt[n-1]<=w)
        return dp[w][n]=(ll)max(val[n-1]+knapsack(val,wt,w-wt[n-1],n-1),knapsack(val,wt,w,n-1));
    else 
        return dp[w][n]=(ll)knapsack(val,wt,w,n-1);
}


void solve()
{
    int n,w;cin>>n>>w;
    vll val(n),wt(n);for(int i=0;i<n;i++)cin>>wt[i]>>val[i];
    memset(dp,-1,sizeof(dp));
    cout<<knapsack(val,wt,w,n)<<endl;

} 


int main()
{   
    #ifndef ONLINE_JUDGE 
        freopen("input.txt", "r", stdin); 
        freopen("output.txt", "w", stdout); 
    #endif 
    FIO;
    ll test;test=1;
    // cin>>test;for(ll i=1;i<=test;i++)
    solve();
    return 0;
}





template<typename T>
ostream& operator<<(ostream &out,const vector<T> &v){
    int i=0;
    for(T x:v){
        out<<x;
        (i++!=v.size())?out<<' ':out<<'\n';    
    }
    return out;
}


template<typename T>
istream& operator>>(istream &in,vector<T> &v){
    for(T &i:v)
        in>>i;
    return in;
}

Measured memory_bytes: 85656