def dequeue(queue, k)
  max = 0
  fetch_count = [queue.size, k].min
  0.upto(fetch_count) do |a|
    0.upto(fetch_count) do |b|
      break if a + b > fetch_count
      arr = []
      q = queue.dup
      a.times { arr << q.shift }
      b.times { arr << q.pop }

      arr.sort!

      dump_count = k - a - b
      while !arr.empty? && dump_count > 0 && arr[0] < 0
        arr.shift
        dump_count -= 1
      end

      max = [max, arr.inject(:+)].max unless arr.empty?
    end
  end
  max
end

n, k = gets.split.map(&:to_i)
queue = gets.split.map(&:to_i)
puts dequeue(queue, k)