/*
csc -debug D.cs && mono --debug D.exe <<< "6 4
-10 8 2 1 2 6"
*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Reflection;

public class HelloWorld {
    public static void SolveCodeForces() {
        var N = cin.NextInt();
        var K = cin.NextInt();
        var V = cin.LongArray();

        // i => sum [0 .. i)
        var preLeft = new long[N+1];
        for (var i = 1; i <= N; i++)
            preLeft[i] = preLeft[i-1] + V[i-1];

        // i => sum [i .. end]
        var preRight = new long[N+1];
        for (var i = N; i > 0; i--)
            preRight[i-1] = preRight[i] + V[i-1];

        var ans = 0L;
        for (var left = 0; left <= Math.Min(N, K); left++)
            for (var right = 0; right <= Math.Min(N, K); right++) {
                if (left + right > K || left + right > N) continue;

                var picked = new long[left + right];
                for (var i = 0; i < left; i++)
                    picked[i] = V[i];

                for (var i = 0; i < right; i++)
                    picked[i + left] = V[N-i-1];

                Array.Sort(picked, 0, picked.Length);

                var rem = K - left - right;
                var index = -1;
                while (index + 1 < picked.Length && picked[index + 1] < 0 && index + 2 <= rem) index++;

                var sum = 0L;
                for (var i = index+1; i < picked.Length; i++)
                    sum += picked[i];

// System.Console.WriteLine(new {left, right, index, sum, picked=string.Join(" ", picked)});

                ans = Math.Max(ans, sum);
            }

        System.Console.WriteLine(ans);
    }

    static Scanner cin = new Scanner();
    static StringBuilder cout = new StringBuilder();

    static public void Main () {
        SolveCodeForces();
        // IncreaseStack(SolveCodeForces);
        // System.Console.Write(cout.ToString());
    }

    public static void IncreaseStack(ThreadStart action, int stackSize = 128000000)
    {
        var thread = new Thread(action, stackSize);
        thread.Start();
        thread.Join();
    }
}

public static class Helpers {
    public static T[] CreateArray<T>(int length, Func<int, T> itemCreate) {
        var result = new T[length];
        for (var i = 0; i < result.Length; i++)
            result[i] = itemCreate(i);
        return result;
    }
}

public class Scanner
{
    private string[] line = new string[0];
    private int index = 0;

    public string Next() {
        if (line.Length <= index) {
            line = Console.ReadLine().Split(' ');
            index = 0;
        }
        var res = line[index];
        index++;
        return res;
    }

    public int NextInt() {
        return int.Parse(Next());
    }

    public long NextLong() {
        return long.Parse(Next());
    }

    public ulong NextUlong() {
        return ulong.Parse(Next());
    }

    public string[] Array() {
        line = Console.ReadLine().Split(' ');
        index = line.Length;
        return line;
    }

    public int[] IntArray(int emptyPrefixLen = 0) {
        var array = Array();
        var result = new int[emptyPrefixLen + array.Length];
        for (int i = 0; i < array.Length; i++)
            result[emptyPrefixLen + i] = int.Parse(array[i]);
        return result;
    }

    public long[] LongArray() {
        var array = Array();
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = long.Parse(array[i]);
        return result;
    }

    public ulong[] UlongArray() {
        var array = Array();
        var result = new ulong[array.Length];
        for (int i = 0; i < array.Length; i++)
            result[i] = ulong.Parse(array[i]);
        return result;
    }
}

Measured memory_bytes: 13396