#include<bits/stdc++.h>
#define ll int
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;

int main()
{ 
    ll n,t;
    cin>>n>>t;

    vector<pair<ll,ll>> v(n);
    for(ll i=0;i<n;i++)
    	cin>>v[i].ff>>v[i].ss;

    sort(v.begin(),v.end());
    vector<ll> dp(t+3000,0);

    for(auto d:v)
    	for(ll i=t-1;i>-1;i--)
    		dp[i+d.ff]=max(dp[i+d.ff],dp[i]+d.ss);

    	cout<<*max_element(dp.begin(),dp.end())<<endl;
}
