def unbounded_knapsack(items, budget)
    table = [0]
    for i in 1..budget
        table[i] = 0
        items.each{|c, v|
            next if c > i
            x = table[i-c] + v
            table[i] = x if x > table[i]
        }
    end
    table[budget]
end

n, budget = gets.split.map &:to_i
items = $<.map{|s| s.split.map(&:to_i).reverse}
p unbounded_knapsack(items, budget)