import java.io._
import java.util.StringTokenizer
import scala.util.control.Breaks.{breakable,break}
import scala.collection.mutable.{Map, Stack, Queue, PriorityQueue}

object Main extends App {
  val in = new InputReader(System.in)
  val pw = new PrintWriter(System.out)

  val N, T = in.next().toInt
  val A = new Array[Int](N+1)
  val B = new Array[Int](N+1)
  for (i <- 1 to N) {
    val a, b = in.next().toInt
    A(i) = a
    B(i) = b
  }

  // 
  val dp = Array.fill[Int](2*T+1)(-1)
  dp(0) = 0

  for (k <- 1 to N) {
    val t = A(k)
    val score = B(k)

    if (T >= t) {
      for (i <- (T - t)*2 + 1 to 2*T by 2) {
        if(dp(i-1) != -1)
          dp(i) = Math.max(dp(i), dp(i-1) + score)
      }

      for (i <- (0 to (T - t)*2).reverse) {
        if(dp(i) != -1) {
          dp(i+2*t) = Math.max(dp(i+2*t), dp(i) + score)
        }
      }
    }
    else {
      for (i <- 1 to 2*T by 2) {
        if(dp(i-1) != -1)
          dp(i) = Math.max(dp(i), dp(i-1) + score)
      }
    }
  }

//  println(dp.deep)

  println(dp.max)
}

object Sub {
  def print2DimArray[A](mat: Array[Array[A]]): Unit = {
    mat.foreach(lin => println(lin.deep))
  }
}

class InputReader(stream: InputStream) {
  private[this] val reader = new BufferedReader(new InputStreamReader(stream))
  private[this] var tokenizer: StringTokenizer = new StringTokenizer(reader.readLine())
  def next(): String = {
    while (!tokenizer.hasMoreTokens()) {
      tokenizer = new StringTokenizer(reader.readLine())
    }
    tokenizer.nextToken()
  }
}
