N,K=map(int,input().split())
V=list(map(int,input().split()))
if N<=K:
  W=sorted(V)
  h=sum(V)
  for i in range(K-N):
    if W[i]<0:
      h-=W[i]
    else:
      break
else:
  ans=[]
  for i in range(1,K+1):
    for j in range(i+1):
      l=V[0:i-j]+V[N-j:N]
      l.sort()
      H=sum(l)
      for k in range(min(i,K-i)):
        if l[k]<0:
          H-=l[k]
        else:
          break
      ans.append(H)
  h=max(ans)
print(h) 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 if N<=K:
  W=sorted(V)
  h=sum(V)
  for i in range(K-N):
    if W[i]<0:
      h-=W[i]
    else:
      break
else:
  ans=[]
  for i in range(1,K+1):
    for j in range(i+1):
      l=V[0:i-j]+V[N-j:N]
      l.sort()
      H=sum(l)
      for k in range(min(i,K-i)):
        if l[k]<0:
          H-=l[k]
        else:
          break
      ans.append(H)
  h=max(ans) N<=K N K W=sorted(V) W sorted(V) sorted V h=sum(V) h sum(V) sum V for i in range(K-N):
    if W[i]<0:
      h-=W[i]
    else:
      break i range(K-N) range K-N K N if W[i]<0:
      h-=W[i]
    else:
      break W[i]<0 W[i] W i 0 h-=W[i] h W[i] W i break ans=[] ans [] for i in range(1,K+1):
    for j in range(i+1):
      l=V[0:i-j]+V[N-j:N]
      l.sort()
      H=sum(l)
      for k in range(min(i,K-i)):
        if l[k]<0:
          H-=l[k]
        else:
          break
      ans.append(H)
   i range(1,K+1) range 1 K+1 K 1 for j in range(i+1):
      l=V[0:i-j]+V[N-j:N]
      l.sort()
      H=sum(l)
      for k in range(min(i,K-i)):
        if l[k]<0:
          H-=l[k]
        else:
          break
      ans.append(H)
   j range(i+1) range i+1 i 1 l=V[0:i-j]+V[N-j:N] l V[0:i-j]+V[N-j:N] V[0:i-j] V 0:i-j 0 i-j i j V[N-j:N] V N-j:N N-j N j N l.sort() l.sort l sort H=sum(l) H sum(l) sum l for k in range(min(i,K-i)):
        if l[k]<0:
          H-=l[k]
        else:
          break
       k range(min(i,K-i)) range min(i,K-i) min i K-i K i if l[k]<0:
          H-=l[k]
        else:
          break
       l[k]<0 l[k] l k 0 H-=l[k] H l[k] l k break ans.append(H) ans.append ans append H h=max(ans) h max(ans) max ans print(h) print h h=sum(V) sum(V) h H=sum(l) sum(l) H W=sorted(V) sorted(V) W l=V[0:i-j]+V[N-j:N] V[0:i-j]+V[N-j:N] l K=map(int,input().split()) map(int,input().split()) K h-=W[i] W[i] h ans=[] [] ans h=max(ans) max(ans) h N,K=map(int,input().split()) map(int,input().split()) N H-=l[k] l[k] H V=list(map(int,input().split())) list(map(int,input().split())) V
N,K=map(int,input().split())
V=list(map(int,input().split()))
if N<=K:
  W=sorted(V)
  h=sum(V)
  for i in range(K-N):
    if W[i]<0:
      h-=W[i]
    else:
      break
else:
  ans=[]
  for i in range(1,K+1):
    for j in range(i+1):
      l=V[0:i-j]+V[N-j:N]
      l.sort()
      H=sum(l)
      for k in range(min(i,K-i)):
        if l[k]<0:
          H-=l[k]
        else:
          break
      ans.append(H)
  h=max(ans)
print(h)