import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	int n = rint, t = rint;
	X[] xs;
	foreach(i; 0 .. n) xs ~= X(rlong, rlong);
	
	long[][] uf = new long[][](t, n); // t分までに食べ終わる料理での満足度
	long[] vs = new long[](n); // 最後までに注文する料理での満足度
	// 料理を増やしながら様子を見る
	foreach(j, x; xs){
		foreach(i; 0 .. t){
			long u = 0;
			if(i >= x.a) u = max(u, x.b);
			if(i >= 1) u = max(u, uf[i - 1][j]);
			if(j >= 1) u = max(u, uf[i][j - 1]);
			if(i >= x.a && j >= 1) u = max(u, uf[i - x.a][j - 1] + x.b);
			uf[i][j] = u;
		}
		long v = max(uf[t - 1][j], x.b);
		if(j >= 1) v = max(v, vs[j - 1], uf[t - 1][j - 1] + x.b);
		vs[j] = v;
		log("j:", j, uf.map!(q => q[j]), vs[j]);
	}
	
	vs[n - 1].writeln;
	
}
struct X{
	long a, b;
}
	
