from heapq import heappush, heappop, heapify



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

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



# N jewels in dequeue D

# at most K operations

# 1 <= N <= 50

# 1 <= K <= 100

# -10000000 <= Vi <= 10000000



# Operation A, B: Remove left or right

# Operation C, D: Add to left or right



S = 0

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

    for takeL in range(take + 1):

        for takeR in range(take - takeL + 1):

            hand = []

            for i in range(takeL):

                heappush(hand, V[i])

            for i in range(takeR):

                if N - i - 1 < takeL:

                    break

                heappush(hand, V[N- i - 1])

            S = max(sum(hand), S)

            for _ in range(K - take):

                if not hand or hand[0] >= 0:

                    break

                heappop(hand)

                S = max(sum(hand), S)

print(S)



from heapq import heappush, heappop, heapify



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

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



# N jewels in dequeue D

# at most K operations

# 1 <= N <= 50

# 1 <= K <= 100

# -10000000 <= Vi <= 10000000



# Operation A, B: Remove left or right

# Operation C, D: Add to left or right



S = 0

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

    for takeL in range(take + 1):

        takeR = take - takeL

        hand = []

        for i in range(takeL):

            heappush(hand, V[i])

        for i in range(takeR):

            if N - i - 1 < takeL:

                break

            heappush(hand, V[N- i - 1])

        S = max(sum(hand), S)

        for _ in range(K - take):

            if not hand or hand[0] >= 0:

                break

            heappop(hand)

            S = max(sum(hand), S)

print(S)



from heapq import heappush, heappop, heapify

N, K = list(map(int, input().split()))
V = list(map(int, input().split()))
# N jewels in dequeue D
# at most K operations
# 1 <= N <= 50
# 1 <= K <= 100
# -10000000 <= Vi <= 10000000
# Operation A, B: Remove left or right
# Operation C, D: Add to left or right
S = 0
for take in range(min(N, K) + 1):
    for takeL in range(take + 1):
        for takeR in range(take - takeL + 1):
            hand = []
            for i in range(takeL):
                heappush(hand, V[i])
            for i in range(takeR):
                if N - i - 1 < takeL:
                    break
                heappush(hand, V[N - i - 1])
            S = max(sum(hand), S)
            for _ in range(K - take):
                if not hand or hand[0] >= 0:
                    break
                heappop(hand)
                S = max(sum(hand), S)
print(S)

from heapq import heappush, heappop, heapify

N, K = list(map(int, input().split()))
V = list(map(int, input().split()))
# N jewels in dequeue D
# at most K operations
# 1 <= N <= 50
# 1 <= K <= 100
# -10000000 <= Vi <= 10000000
# Operation A, B: Remove left or right
# Operation C, D: Add to left or right
S = 0
for take in range(min(N, K) + 1):
    for takeL in range(take + 1):
        takeR = take - takeL
        hand = []
        for i in range(takeL):
            heappush(hand, V[i])
        for i in range(takeR):
            if N - i - 1 < takeL:
                break
            heappush(hand, V[N - i - 1])
        S = max(sum(hand), S)
        for _ in range(K - take):
            if not hand or hand[0] >= 0:
                break
            heappop(hand)
            S = max(sum(hand), S)
print(S)

-        for takeR in range(take - takeL + 1): -            hand = [] -            for i in range(takeL): -                heappush(hand, V[i]) -            for i in range(takeR): -                if N - i - 1 < takeL: -                    break -                heappush(hand, V[N - i - 1]) +        takeR = take - takeL +        hand = [] +        for i in range(takeL): +            heappush(hand, V[i]) +        for i in range(takeR): +            if N - i - 1 < takeL: +                break +            heappush(hand, V[N - i - 1]) +        S = max(sum(hand), S) +        for _ in range(K - take): +            if not hand or hand[0] >= 0: +                break +            heappop(hand) -            for _ in range(K - take): -                if not hand or hand[0] >= 0: -                    break -                heappop(hand) -                S = max(sum(hand), S)