#include <bits/stdc++.h>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, t;
    cin >> n >> t;
    vector<pair<int, int>> xs(n);
    for (auto& x : xs) {
        cin >> x.first >> x.second;
    }
    sort(xs.begin(), xs.end());
    vector<int> happiness(t+1, 0);
    for (int i = 0; i < n; ++i) {
        int a = xs[i].first, b = xs[i].second;
        happiness[t] = max(happiness[t], happiness[t-1] + b);
        for (int j = t-1; j >= a; --j) {
            happiness[j] = max(happiness[j], happiness[j - a] + b);
        }
    }
    cout << happiness[t] << endl;
    return 0;
}
