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(T+1, N+1)(0)
    
    var t = 0
    while (t < T) {
      var i = 0
      while (i < N) {
        val nextT = (t + A(i)) min T
        dp(nextT)(i+1) = dp(nextT)(i+1) max (dp(t)(i) + B(i))
        dp(t)(i+1) = dp(t)(i+1) max dp(t)(i)
        i += 1
      }
      t += 1
    }

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

}