//////////////////////////////////////
////       ABHINASH GIRI          ////
/////////////////////////////////////
#include<bits/stdc++.h>
using namespace std;
#define pr 4294967296   // 2^32
#define fast ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr)
#define high 1000000001
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             -1e18
#define pinf              1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define e               1000000000
#define w(x)            int t; cin>>t; while(t--)
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define co(x) cout<<(x)<<"\n"
#define endl "\n"
typedef unsigned long int  ul;
typedef unsigned long long int ull;
typedef unsigned long long  int  li;
typedef vector<int> vi;
typedef vector<long long int> vll;
typedef vector<long int> vl;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<long int,long int>> vpl;
typedef vector<pair<long long int,long long int>> vpll;
typedef long long ll;
bool cmp(pair<char,int>a,pair<char,int>b)
{
    if(a.first==b.first)
        return a.second<b.second;
    return a.first>b.first;
}

ll  power(ll  a,ll  b){
    if(b==0)
        return 1;
    if(b==1)
        return a;
    else{
        ll  res=power(a,b/2);
        if(b%2)
        {
            return (res*res*(a));}
        else
        {return (res*res);}
    }
}
ll  gcd(ll  a,ll  b){
    if(b==0)
        return a;
    return gcd(b,a%b);
}

void perm(vector<vector<ll>>v,int& level,vector<bool>options,ll&ans,ll& sum,int &n)
{
    if(n==1)
    {
        ans=max(v[1][1],max(v[1][2],v[1][3]));
        return;
    }
    //cout<<" level is "<<level<<endl;
    if(level==n+1)
    {
        //cout<<" sum "<<sum<<endl;
        ans= max(ans,sum);
        //cout<<" ans "<<ans<<endl;
        return;
    }
    for (int i = 1; i <=3 ; ++i)
    {
        if(!options[i])
        {
            continue;
        }
        sum+=v[level][i];
        //cout<<" selected at level "<<level<<" "<<v[level][i]<<endl;
        vector<bool>opt(4,true);
        opt[i]=false;
        level++;
        perm(v,level,opt,ans,sum,n);
        level--;
        //cout<<" de-selected at level "<<level<<" "<<v[level][i]<<endl;
        sum-=v[level][i];
    }
}
int main() {
    std::chrono::time_point<std::chrono::high_resolution_clock> start_timer, end_timer;
    start_timer = std::chrono::high_resolution_clock::now();
    bool show_time = false;  //  change it to true when needed;
//    #ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
//    #endif

    /* Cook your Code  */
   fast;
   int n,w;
   cin>>n>>w;
   vector<ll> r(w+1,0);
   vector<vector<ll>>v,dp(n+1,r);
   vector<ll> s(3,0);
   v.emplace_back(s);
    for (int j = 0; j <n ; ++j)
    {
        vector<ll> vec(3,0);
        for (int i = 1; i <= 2; ++i)
        {
            cin>>vec[i];

        }
        v.emplace_back(vec);
    }
    for (int i = 1; i <=n ; ++i) {
        for (int j = 1; j <=w ; ++j) {
            if(v[i][1]>j)
            {
                dp[i][j]=dp[i-1][j];
            }
            else
            {
                dp[i][j]=max(dp[i-1][j],v[i][2]+dp[i-1][j-v[i][1]]);
            }
        }
    }
    cout<<dp[n][w]<<endl;
    end_timer = std::chrono::high_resolution_clock::now();
    ll elapsed_time = std::chrono::duration_cast<std::chrono::milliseconds>(end_timer-start_timer).count();
    if(show_time)
    {cout << "\\nElapsed Time: " << elapsed_time << "ms\\n";}

    return 0;
}

Measured memory_bytes: 80256