def func s, l, memo
    if s == @items.size
        @answers << memo
    else
        for i in s...@items.size
            if @items[i][1] <= l
                func(i + 1, l - @items[i][1], memo + @items[i][0])
            else
                @answers << memo
            end
        end
    end
end

n_items, w_limit = gets.chomp.split.map(&:to_i)
@items = []
n_items.times{@items << gets.chomp.split.map(&:to_i)}

@answers = []
func(0, w_limit, 0)
puts @answers.max