n,k=map(int,input().split())
v=list(map(int,input().split()))
ans=0
for a in range(min(k,n)+1):
  for b in range(min(k,n)-a+1):
    t=v[:a]
    t+=v[n-b:]
    t.sort()
    for i in range(k-(a+b)):
      if len(t) and t[0]<0:
        t.pop(0)
    ans=max(ans,sum(t))
print(ans) 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 a in range(min(k,n)+1):
  for b in range(min(k,n)-a+1):
    t=v[:a]
    t+=v[n-b:]
    t.sort()
    for i in range(k-(a+b)):
      if len(t) and t[0]<0:
        t.pop(0)
    ans=max(ans,sum(t)) a range(min(k,n)+1) range min(k,n)+1 min(k,n) min k n 1 for b in range(min(k,n)-a+1):
    t=v[:a]
    t+=v[n-b:]
    t.sort()
    for i in range(k-(a+b)):
      if len(t) and t[0]<0:
        t.pop(0)
    ans=max(ans,sum(t)) b range(min(k,n)-a+1) range min(k,n)-a+1 min(k,n)-a min(k,n) min k n a 1 t=v[:a] t v[:a] v :a a t+=v[n-b:] t v[n-b:] v n-b: n-b n b t.sort() t.sort t sort for i in range(k-(a+b)):
      if len(t) and t[0]<0:
        t.pop(0)
     i range(k-(a+b)) range k-(a+b) k a+b a b if len(t) and t[0]<0:
        t.pop(0)
     len(t) and t[0]<0 len(t) len t t[0]<0 t[0] t 0 0 t.pop(0) t.pop t pop 0 ans=max(ans,sum(t)) ans max(ans,sum(t)) max ans sum(t) sum t print(ans) print ans n,k=map(int,input().split()) map(int,input().split()) n t=v[:a] v[:a] t v=list(map(int,input().split())) list(map(int,input().split())) v ans=0 0 ans ans=max(ans,sum(t)) max(ans,sum(t)) ans t+=v[n-b:] v[n-b:] t k=map(int,input().split()) map(int,input().split()) k
n,k=map(int,input().split())
v=list(map(int,input().split()))
ans=0
for a in range(min(k,n)+1):
  for b in range(min(k,n)-a+1):
    t=v[:a]
    t+=v[n-b:]
    t.sort()
    for i in range(k-(a+b)):
      if len(t) and t[0]<0:
        t.pop(0)
    ans=max(ans,sum(t))
print(ans)
