#include <iostream>
#include <cstdio>
#include <algorithm>
#define N 6005
#define F first
#define S second
using namespace std;

int n, t, mx, d[N];
pair<int, int> a[N];
int main()
{
	int i, j;
	cin >> n >> t;
	for (i = 0; i < n; i++) scanf("%d %d", &a[i].F, &a[i].S);
	sort(a, a + n);
	for (i = 0; i < n; i++) {
        for (j = t - 1; j >= 0; j--) {
			d[j + a[i].F] = max(d[j + a[i].F], d[j] + a[i].S);
        }
	}
	for (i = 0; i < N; i++) mx = max(mx, d[i]);
    cout << mx << endl;
    return 0;
}