import sys

input = sys.stdin.readline

N, K = [int(x) for x in input().split()]

V = [int(x) for x in input().split()]



ans = 0

for i in range(K + 1):

    for j in range(K + 1 - i):

        for k in range(K + 1 - i - j):

            tmp = list()

            tmp.extend(V[:min(i, N)])

            tmp.extend(V[max(i, N - j):N])

            tmp.sort(reverse=True)

            for _ in range(k):

                if len(tmp) > 0 and tmp[-1] < 0:

                    tmp.pop()

            ans = max(ans, sum(tmp))



print(ans)





import sys

input = sys.stdin.readline

N, K = [int(x) for x in input().split()]

V = [int(x) for x in input().split()]



ans = 0

for i in range(K + 1):

    for j in range(K + 1 - i):

        k = K - i - j

        tmp = list()

        tmp.extend(V[:min(i, N)])

        tmp.extend(V[max(i, N - j):N])

        tmp.sort(reverse=True)

        for _ in range(k):

            if len(tmp) > 0 and tmp[-1] < 0:

                tmp.pop()

        ans = max(ans, sum(tmp))



print(ans)





import sys

input = sys.stdin.readline
N, K = [int(x) for x in input().split()]
V = [int(x) for x in input().split()]
ans = 0
for i in range(K + 1):
    for j in range(K + 1 - i):
        for k in range(K + 1 - i - j):
            tmp = list()
            tmp.extend(V[: min(i, N)])
            tmp.extend(V[max(i, N - j) : N])
            tmp.sort(reverse=True)
            for _ in range(k):
                if len(tmp) > 0 and tmp[-1] < 0:
                    tmp.pop()
            ans = max(ans, sum(tmp))
print(ans)

import sys

input = sys.stdin.readline
N, K = [int(x) for x in input().split()]
V = [int(x) for x in input().split()]
ans = 0
for i in range(K + 1):
    for j in range(K + 1 - i):
        k = K - i - j
        tmp = list()
        tmp.extend(V[: min(i, N)])
        tmp.extend(V[max(i, N - j) : N])
        tmp.sort(reverse=True)
        for _ in range(k):
            if len(tmp) > 0 and tmp[-1] < 0:
                tmp.pop()
        ans = max(ans, sum(tmp))
print(ans)

-        for k in range(K + 1 - i - j): -            tmp = list() -            tmp.extend(V[: min(i, N)]) -            tmp.extend(V[max(i, N - j) : N]) -            tmp.sort(reverse=True) -            for _ in range(k): -                if len(tmp) > 0 and tmp[-1] < 0: -                    tmp.pop() -            ans = max(ans, sum(tmp)) +        k = K - i - j +        tmp = list() +        tmp.extend(V[: min(i, N)]) +        tmp.extend(V[max(i, N - j) : N]) +        tmp.sort(reverse=True) +        for _ in range(k): +            if len(tmp) > 0 and tmp[-1] < 0: +                tmp.pop() +        ans = max(ans, sum(tmp))