n, k = 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+1, k-left+1)):
        l = v[:left]
        l+=v[::-1][:right]
        l.sort()
        temp = sum(l)
        for t in range(max(0, min(len(l), k-left-right))):
            if l[t]<0:
                temp-=l[t]
        ans = max(ans, temp)
print(ans) 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 = 0 ans 0 for left in range(min(n, k+1)):
    for right in range(min(n-left+1, k-left+1)):
        l = v[:left]
        l+=v[::-1][:right]
        l.sort()
        temp = sum(l)
        for t in range(max(0, min(len(l), k-left-right))):
            if l[t]<0:
                temp-=l[t]
        ans = max(ans, temp) left range(min(n, k+1)) range min(n, k+1) min n k+1 k 1 for right in range(min(n-left+1, k-left+1)):
        l = v[:left]
        l+=v[::-1][:right]
        l.sort()
        temp = sum(l)
        for t in range(max(0, min(len(l), k-left-right))):
            if l[t]<0:
                temp-=l[t]
        ans = max(ans, temp) right range(min(n-left+1, k-left+1)) range min(n-left+1, k-left+1) min n-left+1 n-left n left 1 k-left+1 k-left k left 1 l = v[:left] l v[:left] v :left left l+=v[::-1][:right] l v[::-1][:right] [::-1] v ::-1 -1 :right right l.sort() l.sort l sort temp = sum(l) temp sum(l) sum l for t in range(max(0, min(len(l), k-left-right))):
            if l[t]<0:
                temp-=l[t]
         t range(max(0, min(len(l), k-left-right))) range max(0, min(len(l), k-left-right)) max 0 min(len(l), k-left-right) min len(l) len l k-left-right k-left k left right if l[t]<0:
                temp-=l[t]
         l[t]<0 l[t] l t 0 temp-=l[t] temp l[t] l t ans = max(ans, temp) ans max(ans, temp) max ans temp print(ans) print ans temp-=l[t] l[t] temp n, k = map(int, input().split()) map(int, input().split()) n ans = 0 0 ans temp = sum(l) sum(l) temp l = v[:left] v[:left] l v = list(map(int, input().split())) list(map(int, input().split())) v ans = max(ans, temp) max(ans, temp) ans k = map(int, input().split()) map(int, input().split()) k l+=v[::-1][:right] v[::-1][:right] l
n, k = 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+1, k-left+1)):
        l = v[:left]
        l+=v[::-1][:right]
        l.sort()
        temp = sum(l)
        for t in range(max(0, min(len(l), k-left-right))):
            if l[t]<0:
                temp-=l[t]
        ans = max(ans, temp)
print(ans)
