object Main extends App {

	import scala.math._

	val temp1 = scala.io.StdIn.readLine.split(" ").map(_.toInt)

	val N = temp1(0)
	val B = temp1(1)
	val s = new Array[Int](N)
	val p = new Array[Int](N)

	var world = Array.ofDim[Int](N+1,B+1)

	def f(x: Int, y: Int): Int = {
		if(x==0) return 0
		if(s(x-1) > y) return world(x-1)(y)
		else max(world(x-1)(y), world(x-1)(y-s(x-1)) + p(x-1))
	}

	for(i<- 0 until N){
		val temp = scala.io.StdIn.readLine.split(" ").map(_.toInt)
		s(i) = temp(0)
		p(i) = temp(1)
	}

	for(i<-0 to B){
		for(j<-0 to N){
			world(j)(i) = f(j,i)
		}
	}

	println(world(N)(B))

}