#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define fi first
#define se second
const int maxn=1e5+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
int dp[maxn],n,t;
pair<int,int> book[maxn];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n>>t;
	int ans=0;
	for(int i=0;i<n;i++) cin>>book[i].fi>>book[i].se;
	sort(book,book+n);
	for(int i=0;i<n;i++)
	{
		for(int j=t-1;j>=0;j--)
		{
			ans=max(ans,dp[j]+book[i].se);
			if(j+book[i].fi<t) 
				dp[j+book[i].fi]=max(dp[j+book[i].fi],dp[j]+book[i].se);
		}
	}
	cout<<ans<<'\n';
    return 0;
}

