from sys import stdin
input = stdin.readline

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

ans = -float("inf")

#i: 左から取る回数
for i in range(targ+1):
    #j: 右を取る回数
    for j in range(targ+1-i):
        get = sorted(V[:i] + V[N-j:])
        tmp = sum(get)
        for k in range(min(K-i-j, i+j)):
            tmp = max(tmp, tmp-get[k])
        
        ans = max(tmp, ans)

print(ans) from sys import stdin input = stdin.readline input stdin.readline stdin readline 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 targ = min(N, K) targ min(N, K) min N K ans = -float("inf") ans -float("inf") float("inf") float "inf" for i in range(targ+1):
    #j: 右を取る回数
    for j in range(targ+1-i):
        get = sorted(V[:i] + V[N-j:])
        tmp = sum(get)
        for k in range(min(K-i-j, i+j)):
            tmp = max(tmp, tmp-get[k])
        
        ans = max(tmp, ans) i range(targ+1) range targ+1 targ 1 for j in range(targ+1-i):
        get = sorted(V[:i] + V[N-j:])
        tmp = sum(get)
        for k in range(min(K-i-j, i+j)):
            tmp = max(tmp, tmp-get[k])
        
        ans = max(tmp, ans) j range(targ+1-i) range targ+1-i targ+1 targ 1 i get = sorted(V[:i] + V[N-j:]) get sorted(V[:i] + V[N-j:]) sorted V[:i] + V[N-j:] V[:i] V :i i V[N-j:] V N-j: N-j N j tmp = sum(get) tmp sum(get) sum get for k in range(min(K-i-j, i+j)):
            tmp = max(tmp, tmp-get[k])
        
         k range(min(K-i-j, i+j)) range min(K-i-j, i+j) min K-i-j K-i K i j i+j i j tmp = max(tmp, tmp-get[k]) tmp max(tmp, tmp-get[k]) max tmp tmp-get[k] tmp get[k] get k ans = max(tmp, ans) ans max(tmp, ans) max tmp ans print(ans) print ans K = map(int, input().split()) map(int, input().split()) K tmp = sum(get) sum(get) tmp get = sorted(V[:i] + V[N-j:]) sorted(V[:i] + V[N-j:]) get targ = min(N, K) min(N, K) targ ans = max(tmp, ans) max(tmp, ans) ans input = stdin.readline stdin.readline input V = list(map(int, input().split())) list(map(int, input().split())) V N, K = map(int, input().split()) map(int, input().split()) N ans = -float("inf") -float("inf") ans tmp = max(tmp, tmp-get[k]) max(tmp, tmp-get[k]) tmp
from sys import stdin
input = stdin.readline

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

ans = -float("inf")

#i: 左から取る回数
for i in range(targ+1):
    #j: 右を取る回数
    for j in range(targ+1-i):
        get = sorted(V[:i] + V[N-j:])
        tmp = sum(get)
        for k in range(min(K-i-j, i+j)):
            tmp = max(tmp, tmp-get[k])
        
        ans = max(tmp, ans)

print(ans)