#include <bits/stdc++.h>
using namespace std;

const int MAXN = 3E3+2;

vector<pair<int,int> > a(MAXN);
int n, T;
int f[MAXN][2*MAXN];

int dp(int i, int j){
	int& ret = f[i][j];
	if(ret != -1) return ret;
	if(i==0) return ret = 0;
	ret = dp(i-1, j);
	if(j >= a[i].first) ret = max(ret, a[i].second + dp(i-1, j-a[i].first));
	return ret;
}


signed main(){
	cin >> n >> T;
	for(int i=1; i<= n; ++i) cin >> a[i].first >> a[i].second;
	sort(a.begin()+1, a.begin()+n+1);
	memset(f, -1, sizeof f);
	int ans = 0;
	for(int i=1; i<= n; ++i){
		ans = max(ans, a[i].second + dp(i-1, T-1));
	}
	cout << ans;
}