#include <bits/stdc++.h>
using namespace std;
int n, t;
int a[3100], b[3100];
int dp[3100][3100][2];
int main(){
cin >> n >> t;
for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
for(int j = 0; j < n; j++){
for(int i = t - 1; i >= 0; i--){
if(i + a[j] < t){
for(int k = 0; k < 2; k++){
dp[i + a[j]][j + 1][k] = max(dp[i + a[j]][j + 1][k], dp[i][j][k] + b[j]);
}
}
for(int k = 0; k < 2; k++){
dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][j][k]);
dp[i][j + 1][k] = max(dp[i][j + 1][k], dp[i][j][k]);
}
dp[i][j + 1][1] = max(dp[i][j + 1][1], dp[i][j][0] + b[j]);
dp[i][j][1] = max(dp[i][j][1], dp[i][j][0]);
}
}
cout << dp[t - 1][n - 1][1] << '\n';
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG4sIHQ7CmludCBhWzMxMDBdLCBiWzMxMDBdOwppbnQgZHBbMzEwMF1bMzEwMF1bMl07CgppbnQgbWFpbigpewogICAgY2luID4+IG4gPj4gdDsKICAgIGZvcihpbnQgaSA9IDA7IGkgPCBuOyBpKyspIGNpbiA+PiBhW2ldID4+IGJbaV07CiAgICBmb3IoaW50IGogPSAwOyBqIDwgbjsgaisrKXsKICAgICAgICBmb3IoaW50IGkgPSB0IC0gMTsgaSA+PSAwOyBpLS0pewogICAgICAgICAgICBpZihpICsgYVtqXSA8IHQpewogICAgICAgICAgICAgICAgZm9yKGludCBrID0gMDsgayA8IDI7IGsrKyl7CiAgICAgICAgICAgICAgICAgICAgZHBbaSArIGFbal1dW2ogKyAxXVtrXSA9IG1heChkcFtpICsgYVtqXV1baiArIDFdW2tdLCBkcFtpXVtqXVtrXSArIGJbal0pOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgICAgIGZvcihpbnQgayA9IDA7IGsgPCAyOyBrKyspewogICAgICAgICAgICAgICAgZHBbaSArIDFdW2pdW2tdID0gbWF4KGRwW2kgKyAxXVtqXVtrXSwgZHBbaV1bal1ba10pOwogICAgICAgICAgICAgICAgZHBbaV1baiArIDFdW2tdID0gbWF4KGRwW2ldW2ogKyAxXVtrXSwgZHBbaV1bal1ba10pOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGRwW2ldW2ogKyAxXVsxXSA9IG1heChkcFtpXVtqICsgMV1bMV0sIGRwW2ldW2pdWzBdICsgYltqXSk7CiAgICAgICAgICAgIGRwW2ldW2pdWzFdID0gbWF4KGRwW2ldW2pdWzFdLCBkcFtpXVtqXVswXSk7CiAgICAgICAgfQogICAgfQogICAgY291dCA8PCBkcFt0IC0gMV1bbiAtIDFdWzFdIDw8ICdcbic7Cn0=