void main() {
    int[] tmp = readln.split.to!(int[]);
    int n = tmp[0], t = tmp[1];
    int[] a = new int[n], b = new int[n];
    foreach (i; 0 .. n) {
        tmp = readln.split.to!(int[]);
        a[i] = tmp[0], b[i] = tmp[1];
    }
    zip(a, b).sort!((t1, t2) => t1[0] > t2[0]);
    int[][] dp = new int[][](n+1, t);
    foreach (i; 0 .. n) {
        dp[i+1][0] = b[i];
        foreach (j; 0 .. t) {
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
            if (j + a[i] < t) {
                dp[i+1][j+a[i]] = max(dp[i+1][j+a[i]], dp[i][j]+b[i]);
            }
        }
    }
    dp[n].reduce!max.writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;