# coding: utf-8

import sys



sr = lambda: sys.stdin.readline().rstrip()

ir = lambda: int(sr())

lr = lambda: list(map(int, sr().split()))



N, K = lr()

V = lr()

scores = [0]

limit = min(N, K)

for i in range(limit+1): # iは左から取り出す個数

    for j in range(limit-i+1): # jは右から取り出す個数

        stone = V[:i] + V[N-j:]

        stone.sort()

        result = sum(stone)

        scores.append(result)

        for k in range(min(len(stone), K-(i+j))): # kは戻す個数

            if stone[k] > 0:

                break

            result -= stone[k] 

            scores.append(result)



answer = max(scores)

print(answer)

# 07
# coding: utf-8

import sys



sr = lambda: sys.stdin.readline().rstrip()

ir = lambda: int(sr())

lr = lambda: list(map(int, sr().split()))



N, K = lr()

V = lr()

answer = 0

limit = min(N, K)

for i in range(limit+1): # iは左から取り出す個数

    for j in range(limit-i+1): # jは右から取り出す個数

        stone = V[:i] + V[N-j:]

        stone.sort()

        result = sum(stone)

        if result > answer:

            answer = result

        for k in range(min(len(stone), K-(i+j))): # kは戻す個数

            if stone[k] > 0:

                break

            result -= stone[k] 

            if result > answer:

                answer = result



print(answer)

# 07
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, K = lr()
V = lr()
scores = [0]
limit = min(N, K)
for i in range(limit + 1):  # iは左から取り出す個数
    for j in range(limit - i + 1):  # jは右から取り出す個数
        stone = V[:i] + V[N - j :]
        stone.sort()
        result = sum(stone)
        scores.append(result)
        for k in range(min(len(stone), K - (i + j))):  # kは戻す個数
            if stone[k] > 0:
                break
            result -= stone[k]
            scores.append(result)
answer = max(scores)
print(answer)
# 07

# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, K = lr()
V = lr()
answer = 0
limit = min(N, K)
for i in range(limit + 1):  # iは左から取り出す個数
    for j in range(limit - i + 1):  # jは右から取り出す個数
        stone = V[:i] + V[N - j :]
        stone.sort()
        result = sum(stone)
        if result > answer:
            answer = result
        for k in range(min(len(stone), K - (i + j))):  # kは戻す個数
            if stone[k] > 0:
                break
            result -= stone[k]
            if result > answer:
                answer = result
print(answer)
# 07

-scores = [0] +answer = 0 -        scores.append(result) +        if result > answer: +            answer = result -            scores.append(result) -answer = max(scores) +            if result > answer: +                answer = result