#include <bits/stdc++.h>
#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#define pb push_back
#define IOS                                                                    \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(0);                                                                  \
  cout.tie(0);cout<<fixed<<setprecision(16);
#define ll long long int
#define ld long double
#define el '\n'
#define El '\n'
#define PI (ld)3.141592653589793238462643383279502884197169399375105820974944
#define inf (ll)1000000000
#define mod (ll)1000000007
#define mod1 (ll)998244353
#define fo(i, n) for (long long i = 0; i < n; i++)
#define pll pair<ll, ll>
#define ml map<ll,ll>
#define vpl vector<pll>
#define vvl vector<vector<ll> >
#define vvpl vector< vector<pll> >
#define ff first
#define ss second
#define pqueue priority_queue< ll >
#define pdqueue priority_queue< ll,vl ,greater< ll > >
#define mem(a,b) memset(a,b,sizeof(a));
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define sz(a) (ll)a.size()
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define vl vector<ll>
//#define x ff
//#define y ss
#define pt(a) for(auto it:a)cout<<it<<" ";cout<<endl;
unsigned seed = std::chrono::system_clock::now().time_since_epoch().count();
using namespace std;

// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << t<<" "; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << v.first << " " << v.second ; }

double gcd(double a, double b) { return a < 0.01 ? b : gcd(fmod(b, a), a); }

vector<ll> parent, rak;

void make_set(ll f){
    fo(i,f+1)parent.pb(i);
    rak.assign(f+1,1);
}

ll find_set(ll v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}

ll union_sets(ll a, ll b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (rak[a] < rak[b])
            swap(a, b);
        parent[b] = a;
        rak[a]+=rak[b];
        return (rak[a]-rak[b])*(rak[b]);
    }
    return 0;
}
struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
}; 

long long bpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)

      res = res * a % m;
      a = a * a % m;
      b >>= 1;
  }
  return res;
}
ll extend_gcd(ll a,ll b,ll &x,ll &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    ll x1,y1;
    ll ans =extend_gcd(b,a%b,x1,y1);
    x=y1;
    y=x1-(a/b)*y1;

    return ans;
}
ll inverse(ll a,ll m){
    ll x,y;
    extend_gcd(m,a,x,y);
    y%=m;
    y+=m;
    y%=m;
    return y;
}

vvl mul(vvl a,vvl b,ll m=mod){
    ll p=sz(a),q=sz(a[0]),r=sz(b[0]);
    vvl v(p,vl(r,0));
    fo(i,p){
        fo(j,r){
            fo(l,q){
                v[i][j]+=a[i][l]*b[l][j]%m;
                v[i][j]%=m;
            }
        }
    }
    return v;
}

vvl mpow(vvl a, ll b) {
  ll n=sz(a);
  vvl v(n,vl(n,0));
  fo(i,n)v[i][i]=1;
  while (b > 0) {
    if (b & 1)
      v = mul(v,a);
      a = mul(a,a);
      b >>= 1;
  }
  return v;
}

unsigned long long fhash( vector<ll> p, ll len ) {
    unsigned long long h = 0xcbf29ce484222325ULL;//cout<<0x100000001b3ULL<<endl;
    for ( ll i = 0; i < len; i++ )
      h = ( h ^ p[i] ) * 0x100000001b3ULL;//cout<<h<<endl;

   return h;
}
/*
const ll N = 1e6+5;
vector<int> lp(N+1,0);
//ll u[N+1];
//int phi[N+1];
vector<int> pr;
void sp(){
    //u[1]=1;
    //\\fo(i,N)phi[i+1]=i+1;
for (ll i=2; i<=N; ++i) {
        if (lp[i] == 0) {
            lp[i] = i;//u[i]=-1;
            pr.push_back (i);
            //phi[i]--;
        }
        for (ll j=0; j<(ll)pr.size() && pr[j]<=lp[i] && i*pr[j]<=N; ++j){
            lp[i * pr[j]] = pr[j];
            //if(lp[i]!=pr[j])u[i*pr[j]]=-u[i];
            //else u[i*pr[j]]=0;
            //if(lp[i]!=pr[j])phi[i*pr[j]]=phi[i]*phi[pr[j]];
            //else phi[i*pr[j]]=phi[i]*pr[j];
        }
    }
}*/


ll kv;
ll t,n,x,y,h,k,z,p,q,w;
string s,s1,s2;
//vvl v;
//vl vis,d,f;
ll dp[200][200000];
int main() {
    IOS;
    cin>>n>>h;
    vl w(n),v(n);
    fo(i,n)cin>>w[i]>>v[i];

    fo(i,n+1){
        fo(j,h+1){
            if(i==0||j==0)continue;
            dp[i][j]=dp[i-1][j];
            if(j<w[i-1])continue;
            dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+v[i-1]);
        }
    }
    //fo(i,n+1){fo(j,h+1)cout<<dp[i][j]<<" ";cout<<endl;}
    cout<<dp[n][h];
    return 0;
}


Measured memory_bytes: 156416