import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto T = s[1];
    auto A = iota(N).map!(_ => readln.split.map!(to!int).array).array;
    A.sort!"a[0] < b[0]";

    auto dp = new int[][](N+1, T+1);

    foreach (i; 0..N) {
        foreach (j; 0..T+1) {
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
            if (j != T) dp[i+1][min(T, j + A[i][0])] = max(dp[i+1][min(T, j + A[i][0])], dp[i][j] + A[i][1]);
        }
    }

    dp[N].reduce!max.writeln;
}