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