(* O(m^3 log m) *)
let n, k = Scanf.scanf " %d %d" @@ fun a b -> a, b
let vs = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let ans = ref 0
let m = min n k
let f a b =
  let xs = Array.init (a + b) (fun i -> if i < a then vs.(i) else vs.(n - 1 - i + a)) in
  let sum = ref @@ Array.fold_left (+) 0 xs in
  Array.sort (-) xs;
  let i = ref 0 in
  let c = min (a + b) (k - a - b) in
  while !i < c && xs.(!i) < 0 do sum := !sum - xs.(!i); incr i done;
  !sum
let _ =
  for a = 0 to m do
    for b = 0 to m - a do ans := max !ans @@ f a b done done;
  Printf.printf "%d\n" !ans