module S = Set.Make (struct type t = int * int let compare = compare end)

let () =
    let split s =
        let rec loop i cur flag acc =
            if i = String.length s then ( if flag then cur :: acc else acc) else (
                match flag, s.[i] with
                | true,  ' ' -> loop (i + 1) "" false (cur :: acc)
                | false, ' ' -> loop (i + 1) "" false acc
                | true,  v   -> loop (i + 1) (Printf.sprintf "%s%c" cur v) true acc
                | false, v   -> loop (i + 1) (Printf.sprintf "%s%c" cur v) true acc
            )
        in
        List.map int_of_string (List.rev (loop 0 "" false []))
    in
    let main () =
        let n, k = Scanf.sscanf (read_line ()) "%d %d" (fun n k -> n, k) in
        let v = Array.of_list (split (read_line ())) in
        let calc l r k =
            let rec loop i acc =
                if i = l then acc else loop (i + 1) (v.(i) :: acc)
            in
            let acc = loop 0 [] in
            let rec loop i acc =
                if i = r then acc else loop (i - 1) (v.(i) :: acc)
            in
            let acc = loop (n - 1) acc in
            let l = List.sort compare acc in
            let rec drop i list =
                if i = 0 then list else
                    match list with
                    | [] -> []
                    | hd :: tl -> if hd < 0 then drop (i - 1) tl else (hd :: tl)
            in
            List.fold_left (+) 0 (drop k l)
        in
        let rec loop k mx sets =
            if k < 0 then mx else
                let mx, next =
                    S.fold (fun (l, r) (mx, next) ->
                        let mx = max mx (calc l r k) in
                        let next = if l <= r then S.add (l+1, r) next else next in
                        let next = if l <  r then S.add (l, r-1) next else next in
                        mx, next) sets (mx, S.empty)
                in
                loop (k - 1) mx next
        in
        let init = S.add (0, n - 1) S.empty in
        let ans = loop k 0 init in
        Printf.printf "%d\n" ans
    in
    main ()