n,k=map(int,input().split())
a=list(map(int,input().split()))
g=0
for i in range(0,min(n,k)):
    for j in range(0,min(k-i,n-i)):
        s=sorted(a[:i]+a[n-j:])
        p=sum(s)
        t=i+j
        c=0
        while len(s)>=c+1 and t+1<=k:
            if s[c]<0:
                p-=s[c]
                c+=1
                t+=1
            else:
                break
        g=max(g,p)
print(g)