n,k=map(int,input().split())
v=list(map(int,input().split()))
finans=0
for l in range(n+1):
  for r in range(n-l+1):
    if l+r>k:
      continue
    ans=[]
    for i in range(l):
      ans.append(v[i])
    for i in range(n-1,n-r-1,-1):
      ans.append(v[i])
    ans.sort()
    i=-1
    for i in range(min(len(ans),k-(r+l))):
      if ans[i]>0:
        i-=1
        break
    ans1=0
    for j in range(i+1,len(ans)):
      ans1+=ans[j]
    finans=max(finans,ans1)
print(finans) 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 finans=0 finans 0 for l in range(n+1):
  for r in range(n-l+1):
    if l+r>k:
      continue
    ans=[]
    for i in range(l):
      ans.append(v[i])
    for i in range(n-1,n-r-1,-1):
      ans.append(v[i])
    ans.sort()
    i=-1
    for i in range(min(len(ans),k-(r+l))):
      if ans[i]>0:
        i-=1
        break
    ans1=0
    for j in range(i+1,len(ans)):
      ans1+=ans[j]
    finans=max(finans,ans1) l range(n+1) range n+1 n 1 for r in range(n-l+1):
    if l+r>k:
      continue
    ans=[]
    for i in range(l):
      ans.append(v[i])
    for i in range(n-1,n-r-1,-1):
      ans.append(v[i])
    ans.sort()
    i=-1
    for i in range(min(len(ans),k-(r+l))):
      if ans[i]>0:
        i-=1
        break
    ans1=0
    for j in range(i+1,len(ans)):
      ans1+=ans[j]
    finans=max(finans,ans1) r range(n-l+1) range n-l+1 n-l n l 1 if l+r>k:
      continue
     l+r>k l+r l r k continue ans=[] ans [] for i in range(l):
      ans.append(v[i])
     i range(l) range l ans.append(v[i]) ans.append ans append v[i] v i for i in range(n-1,n-r-1,-1):
      ans.append(v[i])
     i range(n-1,n-r-1,-1) range n-1 n 1 n-r-1 n-r n r 1 -1 ans.append(v[i]) ans.append ans append v[i] v i ans.sort() ans.sort ans sort i=-1 i -1 for i in range(min(len(ans),k-(r+l))):
      if ans[i]>0:
        i-=1
        break
     i range(min(len(ans),k-(r+l))) range min(len(ans),k-(r+l)) min len(ans) len ans k-(r+l) k r+l r l if ans[i]>0:
        i-=1
        break
     ans[i]>0 ans[i] ans i 0 i-=1 i 1 break ans1=0 ans1 0 for j in range(i+1,len(ans)):
      ans1+=ans[j]
     j range(i+1,len(ans)) range i+1 i 1 len(ans) len ans ans1+=ans[j] ans1 ans[j] ans j finans=max(finans,ans1) finans max(finans,ans1) max finans ans1 print(finans) print finans finans=max(finans,ans1) max(finans,ans1) finans i=-1 -1 i finans=0 0 finans ans=[] [] ans ans1=0 0 ans1 i-=1 1 i v=list(map(int,input().split())) list(map(int,input().split())) v k=map(int,input().split()) map(int,input().split()) k n,k=map(int,input().split()) map(int,input().split()) n ans1+=ans[j] ans[j] ans1
n,k=map(int,input().split())
v=list(map(int,input().split()))
finans=0
for l in range(n+1):
  for r in range(n-l+1):
    if l+r>k:
      continue
    ans=[]
    for i in range(l):
      ans.append(v[i])
    for i in range(n-1,n-r-1,-1):
      ans.append(v[i])
    ans.sort()
    i=-1
    for i in range(min(len(ans),k-(r+l))):
      if ans[i]>0:
        i-=1
        break
    ans1=0
    for j in range(i+1,len(ans)):
      ans1+=ans[j]
    finans=max(finans,ans1)
print(finans)