from collections import deque



inputs = open(0).readlines()

n, k = list(map(int, inputs[0].split()))

V = deque(list(map(int, inputs[1].split())))

def calc(ii, jj, kk):

    W = []

    for i in range(ii):

        W.append(V[i])

    for j in range(jj):

        W.append(V[-j-1])

    W.sort(reverse=True)

    for _ in range(kk):

        if W[-1] < 0:

            W.pop()

    return sum(W)



ans = 0

for i in range(min(n, k)+1):

    for j in range(min(n, k)+1-i):

        for k_ in range(min(i+j, k+1-i-j)):

            ans = max(ans, calc(i, j, k_))

print(ans)
n, k, *V = list(map(int, open(0).read().split()))

def calc(i, j, k):

    W = sorted(V[:i] + V[:-j-1:-1], reverse=True)

    for _ in range(k):

        if W[-1] < 0:

            W.pop()

    return sum(W)



ans = 0

r = min(n, k)+1

for i in range(r):

    for j in range(r-i):

        for k_ in range(min(i+j, k+1-i-j)):

            ans = max(ans, calc(i, j, k_))

print(ans)
from collections import deque

inputs = open(0).readlines()
n, k = list(map(int, inputs[0].split()))
V = deque(list(map(int, inputs[1].split())))


def calc(ii, jj, kk):
    W = []
    for i in range(ii):
        W.append(V[i])
    for j in range(jj):
        W.append(V[-j - 1])
    W.sort(reverse=True)
    for _ in range(kk):
        if W[-1] < 0:
            W.pop()
    return sum(W)


ans = 0
for i in range(min(n, k) + 1):
    for j in range(min(n, k) + 1 - i):
        for k_ in range(min(i + j, k + 1 - i - j)):
            ans = max(ans, calc(i, j, k_))
print(ans)

n, k, *V = list(map(int, open(0).read().split()))


def calc(i, j, k):
    W = sorted(V[:i] + V[: -j - 1 : -1], reverse=True)
    for _ in range(k):
        if W[-1] < 0:
            W.pop()
    return sum(W)


ans = 0
r = min(n, k) + 1
for i in range(r):
    for j in range(r - i):
        for k_ in range(min(i + j, k + 1 - i - j)):
            ans = max(ans, calc(i, j, k_))
print(ans)

-from collections import deque - -inputs = open(0).readlines() -n, k = list(map(int, inputs[0].split())) -V = deque(list(map(int, inputs[1].split()))) +n, k, *V = list(map(int, open(0).read().split())) -def calc(ii, jj, kk): -    W = [] -    for i in range(ii): -        W.append(V[i]) -    for j in range(jj): -        W.append(V[-j - 1]) -    W.sort(reverse=True) -    for _ in range(kk): +def calc(i, j, k): +    W = sorted(V[:i] + V[: -j - 1 : -1], reverse=True) +    for _ in range(k): -for i in range(min(n, k) + 1): -    for j in range(min(n, k) + 1 - i): +r = min(n, k) + 1 +for i in range(r): +    for j in range(r - i):