using System;
using System.Collections.Generic;
using System.Linq;
using static Input;
public class Hello
{
    private const long INF = 1000000007;
    private struct Pair { public long x, y; public Pair(long xx, long yy) { x = xx; y = yy; } }
    public static void Main()
    {
        int N = NextInt();
        int K = NextInt();
        int[] V = LineInt();
        //右からK回、左からK回の組み合わせ
        Dictionary<int, Dictionary<int, long>> d0 = new Dictionary<int, Dictionary<int, long>>();
        Dictionary<int, Dictionary<int, long>> d1 = new Dictionary<int, Dictionary<int, long>>();

        if (N == 1)
        {
            if (V[0] < 0) { Console.WriteLine(0); return; }
            else { Console.WriteLine(V[0]); return; }
        }

        for (int i = 0; i < N; i++)
        {
            //とりあえずiまで足してみる
            //許すならマイナスを追い出していく
            PriorityQueue<int, int> Minus = new PriorityQueue<int, int>();
            int sum = 0;
            for (int x = 0; x <= i; x++)
            {
                if (V[x] < 0) { Minus.Add(V[x], V[x]); }
                sum += V[x];
            }
            //iまでなので
            d0[i] = new Dictionary<int, long>();
            d0[i][i + 1] = sum;
            //返してみる
            int cost = 0;
            while (Minus.Count() != 0)
            {
                sum -= Minus.Take();
                cost++;
                d0[i][i + cost + 1] = sum;
            }
        }
        Array.Reverse(V);

        for (int i = 0; i < N; i++)
        {
            PriorityQueue<int, int> Minus = new PriorityQueue<int, int>();
            int sum = 0;
            for (int x = 0; x <= i; x++)
            {
                if (V[x] < 0) { Minus.Add(V[x], V[x]); }
                sum += V[x];
            }
            d1[i] = new Dictionary<int, long>();
            d1[i][i + 1] = sum;
            //返してみる
            int cost = 0;
            while (Minus.Count() != 0)
            {
                sum -= Minus.Take();
                cost++;
                d1[i][i + cost + 1] = sum;
            }
        }
        long ans = 0;
        for (int i = 0; i < N; i++)
            for (int j = 0; j < N; j++)
                for (int k0 = 0; k0 <= K; k0++)
                    for (int k1 = 0; k1 <= K; k1++)
                    {
                        if (k0 + k1 > K || i + j + 1 >= N) break;
                        if (!d0[i].ContainsKey(k0)) d0[i][k0] = 0;
                        if (!d1[j].ContainsKey(k1)) d1[j][k1] = 0;
                        ans = Math.Max(ans, d0[i][k0] + d1[j][k1]);
                    }
        Console.WriteLine(ans);
    }

}

public class PriorityQueue<Tkey, Tvalue> where Tkey : IComparable
{
    private List<Tkey> keys = new List<Tkey>();
    private List<Tvalue> values = new List<Tvalue>();
    private int size = 0;
    private static bool Descending;
    private static int Compare(Tkey a, Tkey b) { return (Descending ? a.CompareTo(b) : b.CompareTo(a)); }

    public PriorityQueue(bool b = true) { Clear(); Descending = b; }
    public int Count() { return size; }
    public void Clear() { keys = new List<Tkey>(); values = new List<Tvalue>(); size = 0; }
    public void Add(Tkey e, Tvalue v)
    {
        keys.Add(e);
        values.Add(v);
        int x = size;
        size += 1;
        while (x != 0)
        {
            int par = (x % 2 == 0 ? x - 2 : x - 1) / 2;
            if (Compare(keys[par], e) <= 0) break;
            Tkey a = keys[x]; keys[x] = keys[par]; keys[par] = a;
            Tvalue b = values[x]; values[x] = values[par]; values[par] = b;
            x = par;
        }
    }
    public void Poll()
    {
        Tkey k = keys[size - 1];
        Tvalue v = values[size - 1];
        int x = 0;
        size--;
        if (size == 0) { Clear(); return; }
        keys.RemoveAt(size);
        values.RemoveAt(size);
        while (true)
        {
            int l = x * 2 + 1;
            int r = x * 2 + 2;
            if (size - 1 < l) break;
            int y = 0;
            if (size - 1 == l) { y = l; }
            else if (Compare(keys[l], keys[r]) == 1) { y = r; }
            else { y = l; }
            if (Compare(keys[y], k) > 0) break;
            keys[x] = keys[y];
            values[x] = values[y];
            x = y;
        }
        keys[x] = k;
        values[x] = v;
    }
    public Tvalue Take() { Tvalue ret = values[0]; Poll(); return ret; }
    public Tvalue Peek() { return values[0]; }
    public void Debug()
    {
        Console.Write("key   : ");
        foreach (var k in keys) Console.Write(k + " ");
        Console.WriteLine();
        Console.Write("value : ");
        foreach (var k in values) Console.Write(k + " ");
        Console.WriteLine();
    }
}

public class Input
{
    private static Queue<string> queue = new Queue<string>();
    private static void Confirm() { if (queue.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) queue.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(queue.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(queue.Dequeue()); }
    public static string NextString() { Confirm(); return queue.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(queue.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 13536