N,K=map(int,input().split())
V=list(map(int,input().split()))
r,ans=min(N,K),0
for a in range(r+1):
  for b in range(r-a+1):
    tmp,minus=0,[]
    for i in range(a):
      tmp+=V[i]
      if V[i]<0:
        minus.append(V[i])
    for j in range(b):
      tmp+=V[N-j-1]
      if V[N-j-1]<0:
        minus.append(V[N-j-1])
    tmp-=sum(sorted(minus)[:K-(a+b)])
    ans=max(ans,tmp)
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 r,ans=min(N,K),0 r min(N,K) min N K ans 0 for a in range(r+1):
  for b in range(r-a+1):
    tmp,minus=0,[]
    for i in range(a):
      tmp+=V[i]
      if V[i]<0:
        minus.append(V[i])
    for j in range(b):
      tmp+=V[N-j-1]
      if V[N-j-1]<0:
        minus.append(V[N-j-1])
    tmp-=sum(sorted(minus)[:K-(a+b)])
    ans=max(ans,tmp) a range(r+1) range r+1 r 1 for b in range(r-a+1):
    tmp,minus=0,[]
    for i in range(a):
      tmp+=V[i]
      if V[i]<0:
        minus.append(V[i])
    for j in range(b):
      tmp+=V[N-j-1]
      if V[N-j-1]<0:
        minus.append(V[N-j-1])
    tmp-=sum(sorted(minus)[:K-(a+b)])
    ans=max(ans,tmp) b range(r-a+1) range r-a+1 r-a r a 1 tmp,minus=0,[] tmp 0 minus [] for i in range(a):
      tmp+=V[i]
      if V[i]<0:
        minus.append(V[i])
     i range(a) range a tmp+=V[i] tmp V[i] V i if V[i]<0:
        minus.append(V[i])
     V[i]<0 V[i] V i 0 minus.append(V[i]) minus.append minus append V[i] V i for j in range(b):
      tmp+=V[N-j-1]
      if V[N-j-1]<0:
        minus.append(V[N-j-1])
     j range(b) range b tmp+=V[N-j-1] tmp V[N-j-1] V N-j-1 N-j N j 1 if V[N-j-1]<0:
        minus.append(V[N-j-1])
     V[N-j-1]<0 V[N-j-1] V N-j-1 N-j N j 1 0 minus.append(V[N-j-1]) minus.append minus append V[N-j-1] V N-j-1 N-j N j 1 tmp-=sum(sorted(minus)[:K-(a+b)]) tmp sum(sorted(minus)[:K-(a+b)]) sum sorted(minus)[:K-(a+b)] (minus) sorted minus :K-(a+b) K-(a+b) K a+b a b ans=max(ans,tmp) ans max(ans,tmp) max ans tmp print(ans) print ans minus=0,[] [] minus K=map(int,input().split()) map(int,input().split()) K ans=max(ans,tmp) max(ans,tmp) ans ans=min(N,K),0 0 ans tmp+=V[N-j-1] V[N-j-1] tmp tmp+=V[i] V[i] tmp N,K=map(int,input().split()) map(int,input().split()) N tmp-=sum(sorted(minus)[:K-(a+b)]) sum(sorted(minus)[:K-(a+b)]) tmp r,ans=min(N,K),0 min(N,K) r tmp,minus=0,[] 0 tmp V=list(map(int,input().split())) list(map(int,input().split())) V
N,K=map(int,input().split())
V=list(map(int,input().split()))
r,ans=min(N,K),0
for a in range(r+1):
  for b in range(r-a+1):
    tmp,minus=0,[]
    for i in range(a):
      tmp+=V[i]
      if V[i]<0:
        minus.append(V[i])
    for j in range(b):
      tmp+=V[N-j-1]
      if V[N-j-1]<0:
        minus.append(V[N-j-1])
    tmp-=sum(sorted(minus)[:K-(a+b)])
    ans=max(ans,tmp)
print(ans)