#include <bits/stdc++.h>
 
using namespace std;
#define fr(i,a,b) for (long long int i = (a), _b = (b); i <= _b; i++)
// #define frr(i,a,b) for (int i = (a), _b = (b); i >= _b; i--)
 
// #define repr(i,n) for (long long i = (n) - 1; i >= 0; i--)
// #define foreach(it,ar) for ( typeof(ar.begin()) it = ar.begin(); it != ar.end(); it++ )
// #define fill(ar,val) memset(ar, val, sizeof(ar))
// #define fill0(ar) fill((ar), 0)
// #define fillinf(ar, n) fr(i,0,(n)) ar[i] = INF
// #define debug(x) cout<<#x<<": "<<x<<endl
// #define arr1d(a,n) cout << #a << " : "; fr(,1,n) cout << a[] << ' '; cout << endl;
// #define arr1d0(a,n) cout << #a << " : "; rep(,n) cout << a[] << ' '; cout << endl;
// #define arr2d(a,n,m) cout << #a << " :" << endl; fr(,1,n) {fr(,1,m) cout << a[][__] << ' '; cout << endl;}
// #define arr2d0(a,n,m) cout << #a << " :" << endl; rep(,n) {rep(,m) cout << a[][__] << ' '; cout << endl;}
// #define ull unsigned long long
// #define ll long long int
// #define ld double
// #define ui unsigned int
// #define all(ar) ar.begin(), ar.end()
// #define pb push_back
// #define mp make_pair
// #define ff first
// #define ss second
 
 
// #define PI 3.1415926535897932385
// #define INF 1000111222
// #define EPS 1e-7
// #define MAXN 1000001
// #define MOD 998244353
 
 
//  #include<iostream>
//      #include<vector>
// #include <stdio.h>
// #include<algorithm>
// #include<math.h>
// #include <iomanip>  
// #include <algorithm> 
// #include<bits/stdc++.h>
// #include <iterator>
// using std::string;
// //#include <boost/algorithm/string.hpp> 
#include<bits/stdc++.h>
#include<ratio>
#include <set> 
#include <iterator>
using namespace std;
#define ll long long
#define VV vector
#define vi vector <int>
#define pb push_back
#define bitc  __builtin_popcountl
#define m_p make_pair
#define inf 200000000000000
#define MAXN 100001
#define eps 0.0000000001
#define prime 1000000007
#define ll long long
#define int ll int
using namespace std;
#define S second
#define F first
ll MOD=1e9+7;
#define rep(i,n) for (long long i = 0, _n = (n); i < _n; i++)
long long StringToInteger(string NumberAsString)
{
  long long NumberAsInteger;
  stringstream ss;
  ss << NumberAsString;
  ss >> NumberAsInteger;
  return NumberAsInteger;
}
int ks[MAXN][100];
int dp (int w,int n,vi &ws,vi &vs){
    // cout<<w<<" "<<n<<" "<<ws[1]<<" "<<vs[1];
    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=w;j++)
        {
            if(i==0||j==0)
            {
                ks[j][i]=0;
                // cout<<j<<" "<<i<<" "<<ks[j][i]<<"\n";
            }
            else if(ws[i-1]<=j){
            
            ks[j][i]=max((ks[j-ws[i-1]][i-1])+(vs[i-1]),ks[j][i-1]);
            // cout<<j<<" "<<i<<" "<<ks[j][i]<<" "<< ks[j-ws[i-1]][i-1]<<" "<<(ks[j-ws[i-1]][i-1])+(vs[i-1])<<" "<<vs[i-1]<<" 2"<<"\n";
            }
            else
            {
                ks[j][i]=ks[j][i-1];
                // cout<<j<<" "<<i<<" "<<ks[j][i]<<"\n";
            }
        }
    }
    // cout<<ks[w][0]<<"\n";
    // cout<<ks[w][1]<<"\n";
    // cout<<ks[w][2]<<"\n";
    // cout<<ks[w][3]<<"\n";
    // cout<<ks[w-1][3]<<"\n";
    // cout<<ks[w-1][2]<<"\n";
    return ks[w][n];
 }
 int32_t main()
{   
    
    int n;
    cin>>n;
    int w;
    cin>>w;
    vi ws(n);
    vi vs(n);     
    for(int i=0;i<n;i++)
    {
        cin>>ws[i]>>vs[i];  
    }
    cout<<dp(w,n,ws,vs);

}

Measured memory_bytes: 78336