#include <iostream>
#include <vector>
#include <algorithm>

#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(vec) vec.begin(), vec.end()
#define chmax(x, y) x = max(x, y);

using namespace std;
typedef pair<int, int> P;

int dp[3005][3005];

int main() {
	int N, T;
	cin >> N >> T;
	vector<P> p(N);

	REP(i, N) cin >> p[i].first >> p[i].second;
	sort(ALL(p));

	int ans = 0;

	REP(i, N) {
		REP(j, T) {
			chmax(dp[i + 1][j], dp[i][j]);
			int x = j + p[i].first;
			if (x < T) chmax(dp[i + 1][x], dp[i][j] + p[i].second);
		}
		chmax(ans, dp[i][T - 1] + p[i].second);
	}

	cout << ans << endl;

	return 0;
}