n,k=map(int,input().split())
v=list(map(int, input().split()))
m=min(n,k)
ans=0
for i in range(m+1): #A
  for j in range(m+1-i): #B
    l=[]
    l=l+v[0:i]+v[n-j:n]
    l.sort()
    for kk in range(min(k-i-j, i+j)):
      if l[kk]<0:
        l[kk]=0
    ans=max(ans, sum(l))
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 m=min(n,k) m min(n,k) min n k ans=0 ans 0 for i in range(m+1): #A
  for j in range(m+1-i): #B
    l=[]
    l=l+v[0:i]+v[n-j:n]
    l.sort()
    for kk in range(min(k-i-j, i+j)):
      if l[kk]<0:
        l[kk]=0
    ans=max(ans, sum(l)) i range(m+1) range m+1 m 1 for j in range(m+1-i): #B
    l=[]
    l=l+v[0:i]+v[n-j:n]
    l.sort()
    for kk in range(min(k-i-j, i+j)):
      if l[kk]<0:
        l[kk]=0
    ans=max(ans, sum(l)) j range(m+1-i) range m+1-i m+1 m 1 i l=[] l [] l=l+v[0:i]+v[n-j:n] l l+v[0:i]+v[n-j:n] l+v[0:i] l v[0:i] v 0:i 0 i v[n-j:n] v n-j:n n-j n j n l.sort() l.sort l sort for kk in range(min(k-i-j, i+j)):
      if l[kk]<0:
        l[kk]=0
     kk range(min(k-i-j, i+j)) range min(k-i-j, i+j) min k-i-j k-i k i j i+j i j if l[kk]<0:
        l[kk]=0
     l[kk]<0 l[kk] l kk 0 l[kk]=0 l[kk] l kk 0 ans=max(ans, sum(l)) ans max(ans, sum(l)) max ans sum(l) sum l print(ans) print ans l=l+v[0:i]+v[n-j:n] l+v[0:i]+v[n-j:n] l v=list(map(int, input().split())) list(map(int, input().split())) v n,k=map(int,input().split()) map(int,input().split()) n l=[] [] l ans=max(ans, sum(l)) max(ans, sum(l)) ans k=map(int,input().split()) map(int,input().split()) k m=min(n,k) min(n,k) m ans=0 0 ans
n,k=map(int,input().split())
v=list(map(int, input().split()))
m=min(n,k)
ans=0
for i in range(m+1): #A
  for j in range(m+1-i): #B
    l=[]
    l=l+v[0:i]+v[n-j:n]
    l.sort()
    for kk in range(min(k-i-j, i+j)):
      if l[kk]<0:
        l[kk]=0
    ans=max(ans, sum(l))
print(ans)