import sys
input = lambda : sys.stdin.readline().rstrip()

n, k = map(int, input().split())
v = list(map(int, input().split()))

ans = -float("inf")

left = v[:]
right = v[::-1]

import bisect

for i in range(n + 1):
    for j in range(n + 1 - i):
        if i + j > k:
            continue
        left_and_right = left[:i] + right[:j]
        left_and_right.sort()
        cnt = k - (i + j)
        idx = bisect.bisect_left(left_and_right, 0)
        minus = sum(left_and_right[:min(cnt, idx)])
        ans = max(sum(left_and_right) - minus, ans)

print(ans)
 import sys sys input = lambda : sys.stdin.readline().rstrip() input lambda : sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k v = list(map(int, input().split())) v list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split ans = -float("inf") ans -float("inf") float("inf") float "inf" left = v[:] left v[:] v : right = v[::-1] right v[::-1] v ::-1 -1 import bisect bisect for i in range(n + 1):
    for j in range(n + 1 - i):
        if i + j > k:
            continue
        left_and_right = left[:i] + right[:j]
        left_and_right.sort()
        cnt = k - (i + j)
        idx = bisect.bisect_left(left_and_right, 0)
        minus = sum(left_and_right[:min(cnt, idx)])
        ans = max(sum(left_and_right) - minus, ans) i range(n + 1) range n + 1 n 1 for j in range(n + 1 - i):
        if i + j > k:
            continue
        left_and_right = left[:i] + right[:j]
        left_and_right.sort()
        cnt = k - (i + j)
        idx = bisect.bisect_left(left_and_right, 0)
        minus = sum(left_and_right[:min(cnt, idx)])
        ans = max(sum(left_and_right) - minus, ans) j range(n + 1 - i) range n + 1 - i n + 1 n 1 i if i + j > k:
            continue
         i + j > k i + j i j k continue left_and_right = left[:i] + right[:j] left_and_right left[:i] + right[:j] left[:i] left :i i right[:j] right :j j left_and_right.sort() left_and_right.sort left_and_right sort cnt = k - (i + j) cnt k - (i + j) k i + j i j idx = bisect.bisect_left(left_and_right, 0) idx bisect.bisect_left(left_and_right, 0) bisect.bisect_left bisect bisect_left left_and_right 0 minus = sum(left_and_right[:min(cnt, idx)]) minus sum(left_and_right[:min(cnt, idx)]) sum left_and_right[:min(cnt, idx)] left_and_right :min(cnt, idx) min(cnt, idx) min cnt idx ans = max(sum(left_and_right) - minus, ans) ans max(sum(left_and_right) - minus, ans) max sum(left_and_right) - minus sum(left_and_right) sum left_and_right minus ans print(ans) print ans k = map(int, input().split()) map(int, input().split()) k left_and_right = left[:i] + right[:j] left[:i] + right[:j] left_and_right idx = bisect.bisect_left(left_and_right, 0) bisect.bisect_left(left_and_right, 0) idx n, k = map(int, input().split()) map(int, input().split()) n ans = -float("inf") -float("inf") ans minus = sum(left_and_right[:min(cnt, idx)]) sum(left_and_right[:min(cnt, idx)]) minus input = lambda : sys.stdin.readline().rstrip() lambda : sys.stdin.readline().rstrip() input ans = max(sum(left_and_right) - minus, ans) max(sum(left_and_right) - minus, ans) ans left = v[:] v[:] left v = list(map(int, input().split())) list(map(int, input().split())) v right = v[::-1] v[::-1] right cnt = k - (i + j) k - (i + j) cnt
import sys
input = lambda : sys.stdin.readline().rstrip()

n, k = map(int, input().split())
v = list(map(int, input().split()))

ans = -float("inf")

left = v[:]
right = v[::-1]

import bisect

for i in range(n + 1):
    for j in range(n + 1 - i):
        if i + j > k:
            continue
        left_and_right = left[:i] + right[:j]
        left_and_right.sort()
        cnt = k - (i + j)
        idx = bisect.bisect_left(left_and_right, 0)
        minus = sum(left_and_right[:min(cnt, idx)])
        ans = max(sum(left_and_right) - minus, ans)

print(ans)

