from collections import deque
N,K=map(int,input().split())
V=list(map(int,input().split()))
res=0
for i in range(min(K,N)+1):
    for L in range(i+1):
        R=i-L
        li=[]
        for j in range(L):
            li.append(V[j])
        for j in range(R):
            li.append(V[N-j-1])
        li.sort()
        s=sum(li)
        for k in range(min(K-i,len(li))):
            if(li[k]<0):
                s-=li[k]
            else:
                break
        res=max(s,res)
print(res) from collections import deque 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 res=0 res 0 for i in range(min(K,N)+1):
    for L in range(i+1):
        R=i-L
        li=[]
        for j in range(L):
            li.append(V[j])
        for j in range(R):
            li.append(V[N-j-1])
        li.sort()
        s=sum(li)
        for k in range(min(K-i,len(li))):
            if(li[k]<0):
                s-=li[k]
            else:
                break
        res=max(s,res) i range(min(K,N)+1) range min(K,N)+1 min(K,N) min K N 1 for L in range(i+1):
        R=i-L
        li=[]
        for j in range(L):
            li.append(V[j])
        for j in range(R):
            li.append(V[N-j-1])
        li.sort()
        s=sum(li)
        for k in range(min(K-i,len(li))):
            if(li[k]<0):
                s-=li[k]
            else:
                break
        res=max(s,res) L range(i+1) range i+1 i 1 R=i-L R i-L i L li=[] li [] for j in range(L):
            li.append(V[j])
         j range(L) range L li.append(V[j]) li.append li append V[j] V j for j in range(R):
            li.append(V[N-j-1])
         j range(R) range R li.append(V[N-j-1]) li.append li append V[N-j-1] V N-j-1 N-j N j 1 li.sort() li.sort li sort s=sum(li) s sum(li) sum li for k in range(min(K-i,len(li))):
            if(li[k]<0):
                s-=li[k]
            else:
                break
         k range(min(K-i,len(li))) range min(K-i,len(li)) min K-i K i len(li) len li if(li[k]<0):
                s-=li[k]
            else:
                break
         li[k]<0 li[k] li k 0 s-=li[k] s li[k] li k break res=max(s,res) res max(s,res) max s res print(res) print res res=max(s,res) max(s,res) res V=list(map(int,input().split())) list(map(int,input().split())) V li=[] [] li N,K=map(int,input().split()) map(int,input().split()) N R=i-L i-L R s-=li[k] li[k] s K=map(int,input().split()) map(int,input().split()) K res=0 0 res s=sum(li) sum(li) s
from collections import deque
N,K=map(int,input().split())
V=list(map(int,input().split()))
res=0
for i in range(min(K,N)+1):
    for L in range(i+1):
        R=i-L
        li=[]
        for j in range(L):
            li.append(V[j])
        for j in range(R):
            li.append(V[N-j-1])
        li.sort()
        s=sum(li)
        for k in range(min(K-i,len(li))):
            if(li[k]<0):
                s-=li[k]
            else:
                break
        res=max(s,res)
print(res)