/* imports all std modules {{{*/
import
  std.algorithm,
  std.array,
  std.ascii,
  std.base64,
  std.bigint,
  std.bitmanip,
  std.compiler,
  std.complex,
  std.concurrency,
  std.container,
  std.conv,
  std.csv,
  std.datetime,
  std.demangle,
  std.encoding,
  std.exception,
  std.file,
  std.format,
  std.functional,
  std.getopt,
  std.json,
  std.math,
  std.mathspecial,
  std.meta,
  std.mmfile,
  std.net.curl,
  std.net.isemail,
  std.numeric,
  std.parallelism,
  std.path,
  std.process,
  std.random,
  std.range,
  std.regex,
  std.signals,
  std.socket,
  std.stdint,
  std.stdio,
  std.string,
  std.system,
  std.traits,
  std.typecons,
  std.uni,
  std.uri,
  std.utf,
  std.uuid,
  std.variant,
  std.zip,
  std.zlib;
/*}}}*/

/+---test
2 60
10 10
100 100
---+/
/+---test
3 60
10 10
10 20
10 30
---+/
/+---test
3 60
30 10
30 20
30 30
---+/

void main(string[] args) {
  int N, T;
  readf(" %d %d ", &N, &T);

  struct Item { long c, v; }
  auto items = new Item[N];
  foreach (ref item; items) readf(" %d %d ", &item.c, &item.v);

  auto dp0 = new long[T], dp1 = new long[T];
  foreach (i; 0..N) {
    foreach_reverse (t; 0..T) if (t + items[i].c < T) {
      dp1[t+items[i].c] = dp1[t+items[i].c].max(dp1[t] + items[i].v);
    }

    foreach (t; 0..T) dp1[t] = dp1[t].max(dp0[t] + items[i].v);

    foreach_reverse (t; 0..T) if (t + items[i].c < T) {
      dp0[t+items[i].c] = dp0[t+items[i].c].max(dp0[t] + items[i].v);
    }
  }
  long ans;
  dp0.each!(x => ans = ans.max(x));
  dp1.each!(x => ans = ans.max(x));
  ans.writeln;
}
