#include <bits/stdc++.h>

using namespace std;

int n, t, a[3005], b[3005], dp[3005][2];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n >> t;
	for (int i=0; i<n; i++) {
		cin >> a[i] >> b[i];
		for (int j=t; j>=a[i]; j--) {
			dp[j][1] = max(dp[j][1], dp[j - a[i]][1] + b[i]);
//			cout << "New dp value for " << j << " is " << dp[j][1] << endl;
		}
		for (int j=t; j>=1; j--) dp[j][1] = max(dp[j][1], dp[j - 1][0] + b[i]);
		for (int j=t; j>=a[i]; j--) dp[j][0] = max(dp[j][0], dp[j - a[i]][0] + b[i]);
	}
	cout << max(dp[t][1], dp[t][0]) << endl;
}