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

ans=0
minnk = min(n,k)
for r in range(minnk+1):
    for l in range(minnk+1-r):
        sute = k-(r+l)
        
        temoti = sorted(v[:l] +v[n-r:])
        n_nega = bisect.bisect(temoti,0)
        score = sum(temoti[min(n_nega,sute):])

        if ans<score:
            ans=score
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 import bisect bisect ans=0 ans 0 minnk = min(n,k) minnk min(n,k) min n k for r in range(minnk+1):
    for l in range(minnk+1-r):
        sute = k-(r+l)
        
        temoti = sorted(v[:l] +v[n-r:])
        n_nega = bisect.bisect(temoti,0)
        score = sum(temoti[min(n_nega,sute):])

        if ans<score:
            ans=score r range(minnk+1) range minnk+1 minnk 1 for l in range(minnk+1-r):
        sute = k-(r+l)
        
        temoti = sorted(v[:l] +v[n-r:])
        n_nega = bisect.bisect(temoti,0)
        score = sum(temoti[min(n_nega,sute):])

        if ans<score:
            ans=score l range(minnk+1-r) range minnk+1-r minnk+1 minnk 1 r sute = k-(r+l) sute k-(r+l) k r+l r l temoti = sorted(v[:l] +v[n-r:]) temoti sorted(v[:l] +v[n-r:]) sorted v[:l] +v[n-r:] v[:l] v :l l v[n-r:] v n-r: n-r n r n_nega = bisect.bisect(temoti,0) n_nega bisect.bisect(temoti,0) bisect.bisect bisect bisect temoti 0 score = sum(temoti[min(n_nega,sute):]) score sum(temoti[min(n_nega,sute):]) sum temoti[min(n_nega,sute):] temoti min(n_nega,sute): min(n_nega,sute) min n_nega sute if ans<score:
            ans=score ans<score ans score ans=score ans score print(ans) print ans sute = k-(r+l) k-(r+l) sute temoti = sorted(v[:l] +v[n-r:]) sorted(v[:l] +v[n-r:]) temoti ans=score score ans score = sum(temoti[min(n_nega,sute):]) sum(temoti[min(n_nega,sute):]) score ans=0 0 ans v = list(map(int,input().split())) list(map(int,input().split())) v minnk = min(n,k) min(n,k) minnk n_nega = bisect.bisect(temoti,0) bisect.bisect(temoti,0) n_nega n,k = map(int,input().split()) map(int,input().split()) n k = map(int,input().split()) map(int,input().split()) k
n,k = map(int,input().split())
v = list(map(int,input().split()))
import bisect

ans=0
minnk = min(n,k)
for r in range(minnk+1):
    for l in range(minnk+1-r):
        sute = k-(r+l)
        
        temoti = sorted(v[:l] +v[n-r:])
        n_nega = bisect.bisect(temoti,0)
        score = sum(temoti[min(n_nega,sute):])

        if ans<score:
            ans=score
print(ans)   