(* O(n k^2) *)
Scanf.scanf " %d %d" @@ fun n k ->
  let vs = Array.init n @@ fun _ -> Scanf.scanf " %d" @@ (+) 0 in
  let ans = ref 0 in
  for b = 0 to n do
    let m = k - b in
    if m >= b && m <= n then
      for l = 0 to m do
        let a = Array.make m 100_000_000 in
        let r = m - l in
        let a_i = ref 0 in
        let rec loop_l acc i rest =
          if rest <= 0 then acc
          else
            (a.(!a_i) <- vs.(i); incr a_i;
            loop_l (acc + vs.(i)) (i + 1) (rest - 1)) in
        let rec loop_r acc i rest =
          if rest <= 0 then acc
          else
            let v = vs.(n - 1 - i) in
            a.(!a_i) <- v; incr a_i;
            loop_r (acc + v) (i + 1) (rest - 1) in
        let sum = ref @@ loop_l 0 0 l + loop_r 0 0 r in
        Array.sort (-) a;
        for i = 0 to b - 1 do
          sum := !sum - a.(i)
        done;
        ans := max !ans !sum
    done
  done;
  Printf.printf "%d\n" !ans