import heapq  # heapqライブラリのimport
N,K=map(int,input().split())
V=list(map(int,input().split()))
ans=0
for i in range(1,min(N,K)+1):
 for t in range(i+1):
  B=V[0:i-t]+V[N-t:N] 
  total=sum(B)
  cut=0
  for j in  range(min(i,K-i)):
   heapq.heapify(B)
   cut=min(cut,cut+heapq.heappop(B))
  ans=max(ans,total-cut)
print(ans) import heapq heapq 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 ans=0 ans 0 for i in range(1,min(N,K)+1):
 for t in range(i+1):
  B=V[0:i-t]+V[N-t:N] 
  total=sum(B)
  cut=0
  for j in  range(min(i,K-i)):
   heapq.heapify(B)
   cut=min(cut,cut+heapq.heappop(B))
  ans=max(ans,total-cut) i range(1,min(N,K)+1) range 1 min(N,K)+1 min(N,K) min N K 1 for t in range(i+1):
  B=V[0:i-t]+V[N-t:N] 
  total=sum(B)
  cut=0
  for j in  range(min(i,K-i)):
   heapq.heapify(B)
   cut=min(cut,cut+heapq.heappop(B))
  ans=max(ans,total-cut) t range(i+1) range i+1 i 1 B=V[0:i-t]+V[N-t:N] B V[0:i-t]+V[N-t:N] V[0:i-t] V 0:i-t 0 i-t i t V[N-t:N] V N-t:N N-t N t N total=sum(B) total sum(B) sum B cut=0 cut 0 for j in  range(min(i,K-i)):
   heapq.heapify(B)
   cut=min(cut,cut+heapq.heappop(B))
   j range(min(i,K-i)) range min(i,K-i) min i K-i K i heapq.heapify(B) heapq.heapify heapq heapify B cut=min(cut,cut+heapq.heappop(B)) cut min(cut,cut+heapq.heappop(B)) min cut cut+heapq.heappop(B) cut heapq.heappop(B) heapq.heappop heapq heappop B ans=max(ans,total-cut) ans max(ans,total-cut) max ans total-cut total cut print(ans) print ans ans=0 0 ans total=sum(B) sum(B) total ans=max(ans,total-cut) max(ans,total-cut) ans B=V[0:i-t]+V[N-t:N] V[0:i-t]+V[N-t:N] B N,K=map(int,input().split()) map(int,input().split()) N K=map(int,input().split()) map(int,input().split()) K V=list(map(int,input().split())) list(map(int,input().split())) V cut=0 0 cut cut=min(cut,cut+heapq.heappop(B)) min(cut,cut+heapq.heappop(B)) cut
import heapq  # heapqライブラリのimport
N,K=map(int,input().split())
V=list(map(int,input().split()))
ans=0
for i in range(1,min(N,K)+1):
 for t in range(i+1):
  B=V[0:i-t]+V[N-t:N] 
  total=sum(B)
  cut=0
  for j in  range(min(i,K-i)):
   heapq.heapify(B)
   cut=min(cut,cut+heapq.heappop(B))
  ans=max(ans,total-cut)
print(ans)