from collections import deque
import heapq
N,K=map(int,input().split())
V=list(map(int,input().split()))
ans=0
  
for i in range(0,min(N,K)+1):
  for a in range(i+1):
    b=i-a
    
    l=0
    d=deque(V)
    minus=[]
    
    for j in range(a):
      p=d.popleft()
      l+=p
      if p<0:
        minus.append(p)
    for j in range(b):
      p=d.pop()
      l+=p
      if p<0:
        minus.append(p)
    heapq.heapify(minus)
    for j in range(min(len(minus),K-i)):
      k=heapq.heappop(minus)
      l-=k
    #print(a,b,l)
    ans=max(ans,l)
    
print(ans) from collections import deque 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(0,min(N,K)+1):
  for a in range(i+1):
    b=i-a
    
    l=0
    d=deque(V)
    minus=[]
    
    for j in range(a):
      p=d.popleft()
      l+=p
      if p<0:
        minus.append(p)
    for j in range(b):
      p=d.pop()
      l+=p
      if p<0:
        minus.append(p)
    heapq.heapify(minus)
    for j in range(min(len(minus),K-i)):
      k=heapq.heappop(minus)
      l-=k
    #print(a,b,l)
    ans=max(ans,l)
     i range(0,min(N,K)+1) range 0 min(N,K)+1 min(N,K) min N K 1 for a in range(i+1):
    b=i-a
    
    l=0
    d=deque(V)
    minus=[]
    
    for j in range(a):
      p=d.popleft()
      l+=p
      if p<0:
        minus.append(p)
    for j in range(b):
      p=d.pop()
      l+=p
      if p<0:
        minus.append(p)
    heapq.heapify(minus)
    for j in range(min(len(minus),K-i)):
      k=heapq.heappop(minus)
      l-=k
    #print(a,b,l)
    ans=max(ans,l)
     a range(i+1) range i+1 i 1 b=i-a b i-a i a l=0 l 0 d=deque(V) d deque(V) deque V minus=[] minus [] for j in range(a):
      p=d.popleft()
      l+=p
      if p<0:
        minus.append(p)
     j range(a) range a p=d.popleft() p d.popleft() d.popleft d popleft l+=p l p if p<0:
        minus.append(p)
     p<0 p 0 minus.append(p) minus.append minus append p for j in range(b):
      p=d.pop()
      l+=p
      if p<0:
        minus.append(p)
     j range(b) range b p=d.pop() p d.pop() d.pop d pop l+=p l p if p<0:
        minus.append(p)
     p<0 p 0 minus.append(p) minus.append minus append p heapq.heapify(minus) heapq.heapify heapq heapify minus for j in range(min(len(minus),K-i)):
      k=heapq.heappop(minus)
      l-=k
    #print(a,b,l)
     j range(min(len(minus),K-i)) range min(len(minus),K-i) min len(minus) len minus K-i K i k=heapq.heappop(minus) k heapq.heappop(minus) heapq.heappop heapq heappop minus l-=k l k ans=max(ans,l) ans max(ans,l) max ans l print(ans) print ans p=d.popleft() d.popleft() p l+=p p l ans=max(ans,l) max(ans,l) ans p=d.pop() d.pop() p N,K=map(int,input().split()) map(int,input().split()) N ans=0 0 ans b=i-a i-a b minus=[] [] minus K=map(int,input().split()) map(int,input().split()) K l=0 0 l k=heapq.heappop(minus) heapq.heappop(minus) k l+=p p l l-=k k l V=list(map(int,input().split())) list(map(int,input().split())) V d=deque(V) deque(V) d
from collections import deque
import heapq
N,K=map(int,input().split())
V=list(map(int,input().split()))
ans=0
  
for i in range(0,min(N,K)+1):
  for a in range(i+1):
    b=i-a
    
    l=0
    d=deque(V)
    minus=[]
    
    for j in range(a):
      p=d.popleft()
      l+=p
      if p<0:
        minus.append(p)
    for j in range(b):
      p=d.pop()
      l+=p
      if p<0:
        minus.append(p)
    heapq.heapify(minus)
    for j in range(min(len(minus),K-i)):
      k=heapq.heappop(minus)
      l-=k
    #print(a,b,l)
    ans=max(ans,l)
    
print(ans)