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

const int MAXN = 3000;
int N, T;

pair<int, int> ABs[MAXN];

int64_t DP[MAXN+10][MAXN];

int64_t f(int t, int i) {
    if (i == N) return 0;
    if (DP[t][i] != -1) return DP[t][i];
    int64_t ans = f(t, i+1);
    if (t < T) ans = max(ans, f(min(T+1, t+ABs[i].first), i+1)+ABs[i].second);
    return DP[t][i] = ans;
}

int main() {
    cin >> N >> T;
    for (int i = 0; i < N; ++i) cin >> ABs[i].first >> ABs[i].second;
    sort(ABs, ABs + N);
    memset(DP, -1, sizeof DP);
    cout << f(0, 0) << endl;
}