N,K=map(int,input().split())
vlist=list(map(int,input().split()))

#take i and remove K-i
answer=0
for i in range(K+1):
  if i>N: break
  
  take_cand=[]
  if i==N:
    take_cand=[vlist]
  else:
    for j1 in range(i+1):
      j2=i-j1
      take_cand.append(vlist[:j1]+vlist[N-j2:])
  
  #print(i,take_cand)
  for take in take_cand:
    take.sort(reverse=True)
    for _ in range(K-i):
      if len(take)>0 and take[-1]<0:
        take.pop()
    
    answer=max(sum(take),answer)

print(answer) N,K=map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split K vlist=list(map(int,input().split())) vlist list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split answer=0 answer 0 for i in range(K+1):
  if i>N: break
  
  take_cand=[]
  if i==N:
    take_cand=[vlist]
  else:
    for j1 in range(i+1):
      j2=i-j1
      take_cand.append(vlist[:j1]+vlist[N-j2:])
  
  #print(i,take_cand)
  for take in take_cand:
    take.sort(reverse=True)
    for _ in range(K-i):
      if len(take)>0 and take[-1]<0:
        take.pop()
    
    answer=max(sum(take),answer) i range(K+1) range K+1 K 1 if i>N: break
  
   i>N i N take_cand=[] take_cand [] if i==N:
    take_cand=[vlist]
  else:
    for j1 in range(i+1):
      j2=i-j1
      take_cand.append(vlist[:j1]+vlist[N-j2:])
  
  #print(i,take_cand)
   i==N i N take_cand=[vlist] take_cand [vlist] vlist for j1 in range(i+1):
      j2=i-j1
      take_cand.append(vlist[:j1]+vlist[N-j2:])
  
  #print(i,take_cand)
   j1 range(i+1) range i+1 i 1 j2=i-j1 j2 i-j1 i j1 take_cand.append(vlist[:j1]+vlist[N-j2:]) take_cand.append take_cand append vlist[:j1]+vlist[N-j2:] vlist[:j1] vlist :j1 j1 vlist[N-j2:] vlist N-j2: N-j2 N j2 for take in take_cand:
    take.sort(reverse=True)
    for _ in range(K-i):
      if len(take)>0 and take[-1]<0:
        take.pop()
    
    answer=max(sum(take),answer) take take_cand take.sort(reverse=True) take.sort take sort reverse=True reverse True for _ in range(K-i):
      if len(take)>0 and take[-1]<0:
        take.pop()
    
     _ range(K-i) range K-i K i if len(take)>0 and take[-1]<0:
        take.pop()
    
     len(take)>0 and take[-1]<0 len(take)>0 len(take) len take 0 take[-1]<0 take[-1] take -1 0 take.pop() take.pop take pop answer=max(sum(take),answer) answer max(sum(take),answer) max sum(take) sum take answer print(answer) print answer take_cand=[vlist] [vlist] take_cand N,K=map(int,input().split()) map(int,input().split()) N vlist=list(map(int,input().split())) list(map(int,input().split())) vlist j2=i-j1 i-j1 j2 take_cand=[] [] take_cand answer=max(sum(take),answer) max(sum(take),answer) answer K=map(int,input().split()) map(int,input().split()) K answer=0 0 answer
N,K=map(int,input().split())
vlist=list(map(int,input().split()))

#take i and remove K-i
answer=0
for i in range(K+1):
  if i>N: break
  
  take_cand=[]
  if i==N:
    take_cand=[vlist]
  else:
    for j1 in range(i+1):
      j2=i-j1
      take_cand.append(vlist[:j1]+vlist[N-j2:])
  
  #print(i,take_cand)
  for take in take_cand:
    take.sort(reverse=True)
    for _ in range(K-i):
      if len(take)>0 and take[-1]<0:
        take.pop()
    
    answer=max(sum(take),answer)

print(answer)