# coding: utf-8



import sys

input = sys.stdin.readline



# N = int(input())

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

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

# S = input()



ans = 0

for l in range(N + 1):

    if l > K:

        break



    for r in range(N - l + 1):

        if l + r > K:

            break



        l_list = sorted(D[0 : l])

        r_list = sorted(D[N - r : N])



        for discard_l in range(K - (l + r) + 1):

            for discard_r in range(K - (l + r + discard_l) + 1):

                value = sum(l_list[discard_l:])

                value += sum(r_list[discard_r:])



                ans = max(ans, value)

        

print(ans)

# coding: utf-8



import sys

input = sys.stdin.readline



# N = int(input())

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

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

# S = input()



ans = 0

for l in range(N + 1):

    if l > K:

        break



    for r in range(N - l + 1):

        if l + r > K:

            break



        value_list = D[0 : l] + D[N - r : N]

        value_list.sort()

        

        for i in range(K - (l + r) + 1):

            ans = max(ans, sum(value_list[i:]))

        

print(ans)

# coding: utf-8
import sys

input = sys.stdin.readline
# N = int(input())
N, K = list(map(int, input().split()))
D = [int(x) for x in input().split()]
# S = input()
ans = 0
for l in range(N + 1):
    if l > K:
        break
    for r in range(N - l + 1):
        if l + r > K:
            break
        l_list = sorted(D[0:l])
        r_list = sorted(D[N - r : N])
        for discard_l in range(K - (l + r) + 1):
            for discard_r in range(K - (l + r + discard_l) + 1):
                value = sum(l_list[discard_l:])
                value += sum(r_list[discard_r:])
                ans = max(ans, value)
print(ans)

# coding: utf-8
import sys

input = sys.stdin.readline
# N = int(input())
N, K = list(map(int, input().split()))
D = [int(x) for x in input().split()]
# S = input()
ans = 0
for l in range(N + 1):
    if l > K:
        break
    for r in range(N - l + 1):
        if l + r > K:
            break
        value_list = D[0:l] + D[N - r : N]
        value_list.sort()
        for i in range(K - (l + r) + 1):
            ans = max(ans, sum(value_list[i:]))
print(ans)

-        l_list = sorted(D[0:l]) -        r_list = sorted(D[N - r : N]) -        for discard_l in range(K - (l + r) + 1): -            for discard_r in range(K - (l + r + discard_l) + 1): -                value = sum(l_list[discard_l:]) -                value += sum(r_list[discard_r:]) -                ans = max(ans, value) +        value_list = D[0:l] + D[N - r : N] +        value_list.sort() +        for i in range(K - (l + r) + 1): +            ans = max(ans, sum(value_list[i:]))