object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N, T = sc.nextInt()
    val A, B = new Array[Int](N)
    (0 until N) foreach { i =>
      A(i) = sc.nextInt()
      B(i) = sc.nextInt()
    }

    val dp = Array.fill(N+1, T+1)(0)

    var i = 0
    while (i < N) {
      var t = 0
      while (t < T) {
        val nextT = (t + A(i)) min T
        var j = 0
        while (j <= t) {
          dp(i + 1)(nextT) = dp(i + 1)(nextT) max (dp(i)(j) + B(i))
          j += 1
        }
        dp(i+1)(t) = dp(i+1)(t) max dp(i)(t)

        t += 1
      }
      i += 1
    }

    println(dp.map(_.max).max)
  }

}
