n, k = gets.chomp.split(' ').map(&:to_i)
v = gets.chomp.split(' ').map(&:to_i)

pat = []
for j in 0..k
  for i in 0..j
    
  tmp_v = v.dup
  item = []
  if i != 0
    i.times do |n|
      item << tmp_v.shift
    end
  end
  
  if (j-i) != 0
    (j-i).times do |n|
      item << tmp_v.pop
    end
  end
  
  item.sort!
  if item.empty? == false
    
    (k-j).times do
      if item[0] < 0
        item.shift
      end
      
      break if item.empty?
    end
  end
  
  pat << item.inject(:+)
  
  end
end
pat << 0
p pat.compact.max

