require 'pp'
N, T = gets.split.map(&:to_i)
$dishes = []
class Dish
    include Comparable
    attr_accessor :cost, :value

    def initialize(a, b)
        @cost = a
        @value = b
    end
    
    def <=>(other)
        [self.cost, -self.value] <=> [other.cost, -other.value]
    end
end
N.times do 
    $dishes << Dish.new(*gets.split.map(&:to_i))
end
$dishes.sort!

$memo = Array.new(3000){Array.new(3000)}
def saiki(n, remain)
    return $memo[n][remain] if $memo[n][remain]
    
    if n == N || remain <= 0
        result = 0
    else
        result = [
            saiki(n + 1, remain),
            saiki(n + 1, remain - $dishes[n].cost) + $dishes[n].value
        ].max
    end
    $memo[n][remain] = result
end

p saiki(0, T)