#include <iostream>

using namespace std;

int main(){
    int N, T;
    cin >> N >> T;

    int A[N], B[N];
    bool used[N];
    int m = 0;
    int mi;
    for(int i=0; i<N; i++){
        cin >> A[i] >> B[i];
        used[i] = false;
        m = max(m, B[i]);
        if(m == B[i]) mi = i;
    }

    int dp[N+1][T+1];
    for(int i=0; i<=N; i++){
        for(int j=0; j<=T; j++){
            dp[i][j] = 0;
        }
    }

    for(int i=0; i<N; i++){
        for(int j=0; j<=T; j++){
            if(i == mi){
                dp[i+1][j] = dp[i][j];
                continue;
            }
            if(j-A[i] < 0) dp[i+1][j] = dp[i][j];
            else dp[i+1][j] = max(dp[i][j], dp[i][j-A[i]]+B[i]);
        }
    }

    cout << dp[N][T-1]+B[mi] << endl;

    return 0;
}