/*#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for(int i = (a); i >=(b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
typedef long long int ll;
using namespace std;
ll mod1=1000000007;
ll mod2=67280421310721;
ll mod3=998244353;
ll INF=1e18;

ll binpow1(ll a,ll b){
    ll res=1;
    while (b>0){
        if (b&1)
        res=res*a;
        a=a*a;
        b>>=1;
    }
    return res;
}

ll binpow2(ll a,ll b,ll m){
    a%=m;
    ll res=1;
    while (b>0){
        if (b & 1)
        res=res*a%m;
        a=a*a%m;
        b>>=1;
    }
    return res;
}

ll gcd(ll a,ll b){
    if (b==0)
        return a;
    else
        return gcd(b,a%b);
}

int main()
{ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    ll t=1;
    while(t--)
    {ll n,m,k;
    cin>>n>>m>>k;ll sum=0;vector<ll> v,v1;
    ll a[n];
    FOR(i,0,n)
    {
        cin>>a[i];
    }
    FOR(i,1,n)
    {
        if(a[i]==a[i-1])
        {
            v.pb(i);
        }
    }
    v.pb(n);
    ll g=k-v.size();ll b=0;
    for(auto i=v.begin();i!=v.end();++i)
    {
        if(g>0 && ((*i)-b)>m)
        {
            FOR(j,(b/m)+1,(((*i)-b)/m))
            {
                if(g>0)
                {
                    v1.pb(j*m);
                    g--;
                }
                else
                {
                    v1.pb((*i));
                    break;
                }
            }
        }
        else
        {
            v1.pb((*i));
        }
    }
    b=0;
    for(auto i=v1.begin();i!=v1.end();++i)
    {
        sort(a+b,a+(*i));
        b=(*i)-1;
    }
    for(auto i=v1.begin();i!=v1.end();++i)
    {
        sum=sum+a[(*i)-1]+a[(*i)-2]+a[(*i)-3];
    }
    cout<<sum<<'\n';
    for(auto i=v1.begin();i!=v1.end();++i)
    {
        cout<<*i<<" ";
    }
    cout<<'\n';
    }



	return 0;
}*/

#include <bits/stdc++.h>
#include <string>
#include <cmath>
#include <sstream>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORD(i, a, b) for(int i = (a); i >=(b); i--)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
typedef long long int ll;
using namespace std;
ll mod1=1000000007;
ll mod2=67280421310721;
ll mod3=998244353;
ll INF=1e18;

ll binpow1(ll a,ll b){
    ll res=1;
    while (b>0){
        if (b&1)
        res=res*a;
        a=a*a;
        b>>=1;
    }
    return res;
}

ll binpow2(ll a,ll b,ll m){
    a%=m;
    ll res=1;
    while (b>0){
        if (b & 1)
        res=res*a%m;
        a=a*a%m;
        b>>=1;
    }
    return res;
}

ll gcd(ll a,ll b){
    if (b==0)
        return a;
    else
        return gcd(b,a%b);
}

map<ll,ll> fact(ll n) {
    map<ll,ll> factorization;ll c=0;
    while (n % 2 == 0) {
        c++;
        n /= 2;
    }
    if(c>0)
    {
        factorization.insert({2,c});
    }c=0;
    for (ll d = 3; d * d <= n; d += 2) {
        while (n % d == 0) {
            c++;
            n /= d;
        }
        if(c>0)
    {
        factorization.insert({d,c});
    }c=0;
    }
    if (n > 1)
       {
           factorization.insert({n,1});
       }
    return factorization;
}

int main()
{ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    ll N,W;
    cin>>N>>W;
    pair<ll,ll> w[N];
    FOR(i,0,N)
    {
        cin>>w[i].first;
        cin>>w[i].second;
    }
    ll dp[N][W+1];
    FOR(i,0,W+1)
    {
        if(w[0].first<=i)
        {
            dp[0][i]=w[0].second;
        }
        else
        {
            dp[0][i]=0;
        }
    }
    FOR(j,1,N)
    {
        FOR(i,0,W+1)
        {
            if(w[j].first<=i)
        {
            dp[j][i]=max(w[j].second+dp[j-1][i-w[j].first],dp[j-1][i]);
        }
        else
        {
            dp[j][i]=dp[j-1][i];
        }
        }
    }
    cout<<dp[N-1][W]<<'\n';
	return 0;
}

























Measured memory_bytes: 81584