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