N, K = gets.chomp.split.map(&:to_i)
V = gets.chomp.split.map(&:to_i)
# T = gets.chomp.chars
# N, K = gets.chomp..to_i

def solve
  ans = 0  
  0.upto([K, N].min).each do |k| # k is the count of extract operation
    0.upto(k).each do |l|  # l is the count of left.
      r = k - l # r is the count of r
      minus = []
      sum = 0
      0.upto(l-1).each do |i|
        if V[i] < 0
          minus << V[i]
        end
        sum += V[i]
      end
      (N-r).upto(N-1).each do |i|
        if V[i] < 0
          minus << V[i]
        end
        sum += V[i]
      end
      minus.sort!  # increasing order
      # Now, we can revert item [K-k, minus.size] times.
      cnt = [K-k, minus.size].min
      cnt.times do |i|
        sum -= minus[i]
      end
      
      if (ans < sum)
        ans = sum
      end
    end
  end
  
  p ans
end

solve