#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>

#define ll long long
#define ld long double
#define mp make_pair
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
 
    int n, t;
    cin>>n>>t;
    vector<pair<int, int>> a(n);
    for (int i = 0; i<n; i++) cin>>a[i].first>>a[i].second;
    sort(a.begin(), a.end());
    vector<int> dp(t+1);
    dp[0] = 0;
    int best = 0;
    for (int i = 0; i<n; i++)
    {
        best = max(best, dp[t-1]+a[i].second);
        for (int j = t-1; j>=a[i].first; j--) dp[j] = max(dp[j], dp[j-a[i].first] + a[i].second);
    }
    cout<<best;
}