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

ans=0
for i in range(min(k,n)+1):
    for j in range(min(k,n)-i+1):
        t=sorted(v[:i]+v[:~j:-1])
        for l in range(min(min(n,k)-i-j,len(t))):
            if t[l]<0:
                t[l]=0
        ans=max(ans,sum(t))

print(ans)