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

    println(dp(T)(N))
  }

}
