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

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



ans = 0

A = 0

while A <= min(K, N):

    B = 0

    lst2 = []

    while B <= min(K, N) - A:

        lst2 = lst[:A]+lst[N-B:]

        lst2.sort()

        count = 0

        for i in range(len(lst2)):

            if lst2[i] <= 0 and i+1 <= K - A - B:

                pass

            else:

                count += lst2[i]

        ans = max(ans, count)

        B += 1

    A += 1



print (ans)

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

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



ans = 0

for left in range(min(N, K) + 1):

    for right in range(min(N - left, K - left) + 1):

        tmp = V[:left] + V[N - right:]

        tmp.sort()

        score = 0

        count = K - left - right

        for i in tmp:

            if count <= 0:

                score += i

            else:

                if i < 0:

                    count -= 1

                else:

                    score += i

        # print (left, right, score, tmp)

        ans = max(ans, score)



print (ans)
N, K = list(map(int, input().split()))
lst = list(map(int, input().split()))
ans = 0
A = 0
while A <= min(K, N):
    B = 0
    lst2 = []
    while B <= min(K, N) - A:
        lst2 = lst[:A] + lst[N - B :]
        lst2.sort()
        count = 0
        for i in range(len(lst2)):
            if lst2[i] <= 0 and i + 1 <= K - A - B:
                pass
            else:
                count += lst2[i]
        ans = max(ans, count)
        B += 1
    A += 1
print(ans)

N, K = list(map(int, input().split()))
V = list(map(int, input().split()))
ans = 0
for left in range(min(N, K) + 1):
    for right in range(min(N - left, K - left) + 1):
        tmp = V[:left] + V[N - right :]
        tmp.sort()
        score = 0
        count = K - left - right
        for i in tmp:
            if count <= 0:
                score += i
            else:
                if i < 0:
                    count -= 1
                else:
                    score += i
        # print (left, right, score, tmp)
        ans = max(ans, score)
print(ans)

-lst = list(map(int, input().split())) +V = list(map(int, input().split())) -A = 0 -while A <= min(K, N): -    B = 0 -    lst2 = [] -    while B <= min(K, N) - A: -        lst2 = lst[:A] + lst[N - B :] -        lst2.sort() -        count = 0 -        for i in range(len(lst2)): -            if lst2[i] <= 0 and i + 1 <= K - A - B: -                pass +for left in range(min(N, K) + 1): +    for right in range(min(N - left, K - left) + 1): +        tmp = V[:left] + V[N - right :] +        tmp.sort() +        score = 0 +        count = K - left - right +        for i in tmp: +            if count <= 0: +                score += i -                count += lst2[i] -        ans = max(ans, count) -        B += 1 -    A += 1 +                if i < 0: +                    count -= 1 +                else: +                    score += i +        # print (left, right, score, tmp) +        ans = max(ans, score)