import bisect



N,K = list(map(int,input().split()))

V = list(map(int,input().split()))



ans = 0



if N < K :

    pp = K

    K = N

else :

    pp = K

for a in range(1,K+1) :

    for i in range(a+1) :

        G = []

        G.extend(V[:i])

        G.extend(V[len(V)-(a-i):])

        G.append(0)

        G = sorted(G)

        #bi = bisect.bisect(G,0)

        #G = G[min(bi-1,K-a):]



        cnt = 0

        calc = 0

        for i in range(len(G)) :

            if G[i] < 0 :

                if cnt < pp-a :

                    cnt += 1

                else :

                    calc += G[i]

            else :

                calc += G[i]





        ans = max(ans,calc)



print(ans)

N,K = list(map(int,input().split()))

V = list(map(int,input().split()))



ans = 0



P = min(N,K)



for a in range(1,P+1) :

    for i in range(a+1) :

        cnt = 0

        calc = 0

        GET = V[:i] + V[N-(a-i):]

        GET = sorted(GET)

        

        for g in GET :

            if (g < 0) and (cnt < K-a) :

                cnt += 1

            else :

                calc += g

        

        ans = max(ans, calc)

print(ans)

import bisect

N, K = list(map(int, input().split()))
V = list(map(int, input().split()))
ans = 0
if N < K:
    pp = K
    K = N
else:
    pp = K
for a in range(1, K + 1):
    for i in range(a + 1):
        G = []
        G.extend(V[:i])
        G.extend(V[len(V) - (a - i) :])
        G.append(0)
        G = sorted(G)
        # bi = bisect.bisect(G,0)
        # G = G[min(bi-1,K-a):]
        cnt = 0
        calc = 0
        for i in range(len(G)):
            if G[i] < 0:
                if cnt < pp - a:
                    cnt += 1
                else:
                    calc += G[i]
            else:
                calc += G[i]
        ans = max(ans, calc)
print(ans)

N, K = list(map(int, input().split()))
V = list(map(int, input().split()))
ans = 0
P = min(N, K)
for a in range(1, P + 1):
    for i in range(a + 1):
        cnt = 0
        calc = 0
        GET = V[:i] + V[N - (a - i) :]
        GET = sorted(GET)
        for g in GET:
            if (g < 0) and (cnt < K - a):
                cnt += 1
            else:
                calc += g
        ans = max(ans, calc)
print(ans)

-import bisect - -if N < K: -    pp = K -    K = N -else: -    pp = K -for a in range(1, K + 1): +P = min(N, K) +for a in range(1, P + 1): -        G = [] -        G.extend(V[:i]) -        G.extend(V[len(V) - (a - i) :]) -        G.append(0) -        G = sorted(G) -        # bi = bisect.bisect(G,0) -        # G = G[min(bi-1,K-a):] -        for i in range(len(G)): -            if G[i] < 0: -                if cnt < pp - a: -                    cnt += 1 -                else: -                    calc += G[i] +        GET = V[:i] + V[N - (a - i) :] +        GET = sorted(GET) +        for g in GET: +            if (g < 0) and (cnt < K - a): +                cnt += 1 -                calc += G[i] +                calc += g