f=lambda:map(int,input().split())
n,k=f()
l=list(f())
v=0
m=min(n,k)
from bisect import *
for i in range(m+1):
  for j in range(m+1-i):
    s=sorted(l[:i]+l[n-j:])
    v=max(v,sum(s[min(bisect_left(s,0),k-i-j):]))
print(v) f=lambda:map(int,input().split()) f lambda:map(int,input().split()) map(int,input().split()) map int input().split() ().split () input split n,k=f() n f() f k l=list(f()) l list(f()) list f() f v=0 v 0 m=min(n,k) m min(n,k) min n k from bisect import * for i in range(m+1):
  for j in range(m+1-i):
    s=sorted(l[:i]+l[n-j:])
    v=max(v,sum(s[min(bisect_left(s,0),k-i-j):])) i range(m+1) range m+1 m 1 for j in range(m+1-i):
    s=sorted(l[:i]+l[n-j:])
    v=max(v,sum(s[min(bisect_left(s,0),k-i-j):])) j range(m+1-i) range m+1-i m+1 m 1 i s=sorted(l[:i]+l[n-j:]) s sorted(l[:i]+l[n-j:]) sorted l[:i]+l[n-j:] l[:i] l :i i l[n-j:] l n-j: n-j n j v=max(v,sum(s[min(bisect_left(s,0),k-i-j):])) v max(v,sum(s[min(bisect_left(s,0),k-i-j):])) max v sum(s[min(bisect_left(s,0),k-i-j):]) sum s[min(bisect_left(s,0),k-i-j):] s min(bisect_left(s,0),k-i-j): min(bisect_left(s,0),k-i-j) min bisect_left(s,0) bisect_left s 0 k-i-j k-i k i j print(v) print v f=lambda:map(int,input().split()) lambda:map(int,input().split()) f v=max(v,sum(s[min(bisect_left(s,0),k-i-j):])) max(v,sum(s[min(bisect_left(s,0),k-i-j):])) v m=min(n,k) min(n,k) m n,k=f() f() n v=0 0 v s=sorted(l[:i]+l[n-j:]) sorted(l[:i]+l[n-j:]) s k=f() f() k l=list(f()) list(f()) l
f=lambda:map(int,input().split())
n,k=f()
l=list(f())
v=0
m=min(n,k)
from bisect import *
for i in range(m+1):
  for j in range(m+1-i):
    s=sorted(l[:i]+l[n-j:])
    v=max(v,sum(s[min(bisect_left(s,0),k-i-j):]))
print(v)