import sys
input=sys.stdin.readline
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
n,k=NM()
l=L()
ans=0
for a in range(n+1):
    for b in range(n-a+1):
        for c in range(a+1):
            for d in range(b+1):
                if a+b+c+d>k:
                    continue
                x=l[:a]
                y=l[-1:-b-1:-1]
                x.sort()
                y.sort()
                ans=max(ans,sum(x[c:])+sum(y[d:]))
print(ans) import sys sys input=sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def N(): return int(input()) N def NM():return map(int,input().split()) NM def L():return list(NM()) L N() for i in range(n) for i in range(n) i range(n) range n for i in range(n) N() N def LN(n):return [N() for i in range(n)] LN n n L() for i in range(n) for i in range(n) i range(n) range n for i in range(n) L() L def LL(n):return [L() for i in range(n)] LL n n n,k=NM() n NM() NM k l=L() l L() L ans=0 ans 0 for a in range(n+1):
    for b in range(n-a+1):
        for c in range(a+1):
            for d in range(b+1):
                if a+b+c+d>k:
                    continue
                x=l[:a]
                y=l[-1:-b-1:-1]
                x.sort()
                y.sort()
                ans=max(ans,sum(x[c:])+sum(y[d:])) a range(n+1) range n+1 n 1 for b in range(n-a+1):
        for c in range(a+1):
            for d in range(b+1):
                if a+b+c+d>k:
                    continue
                x=l[:a]
                y=l[-1:-b-1:-1]
                x.sort()
                y.sort()
                ans=max(ans,sum(x[c:])+sum(y[d:])) b range(n-a+1) range n-a+1 n-a n a 1 for c in range(a+1):
            for d in range(b+1):
                if a+b+c+d>k:
                    continue
                x=l[:a]
                y=l[-1:-b-1:-1]
                x.sort()
                y.sort()
                ans=max(ans,sum(x[c:])+sum(y[d:])) c range(a+1) range a+1 a 1 for d in range(b+1):
                if a+b+c+d>k:
                    continue
                x=l[:a]
                y=l[-1:-b-1:-1]
                x.sort()
                y.sort()
                ans=max(ans,sum(x[c:])+sum(y[d:])) d range(b+1) range b+1 b 1 if a+b+c+d>k:
                    continue
                 a+b+c+d>k a+b+c+d a+b+c a+b a b c d k continue x=l[:a] x l[:a] l :a a y=l[-1:-b-1:-1] y l[-1:-b-1:-1] l -1:-b-1:-1 -1 -b-1 -b b 1 -1 x.sort() x.sort x sort y.sort() y.sort y sort ans=max(ans,sum(x[c:])+sum(y[d:])) ans max(ans,sum(x[c:])+sum(y[d:])) max ans sum(x[c:])+sum(y[d:]) sum(x[c:]) sum x[c:] x c: c sum(y[d:]) sum y[d:] y d: d print(ans) print ans input=sys.stdin.readline sys.stdin.readline input def N(): return int(input()) def N(): return int(input()) N def LN(n):return [N() for i in range(n)] def LN(n):return [N() for i in range(n)] LN def L():return list(NM()) def L():return list(NM()) L def LL(n):return [L() for i in range(n)] def LL(n):return [L() for i in range(n)] LL y=l[-1:-b-1:-1] l[-1:-b-1:-1] y l=L() L() l x=l[:a] l[:a] x ans=0 0 ans ans=max(ans,sum(x[c:])+sum(y[d:])) max(ans,sum(x[c:])+sum(y[d:])) ans def NM():return map(int,input().split()) def NM():return map(int,input().split()) NM n,k=NM() NM() n k=NM() NM() k
import sys
input=sys.stdin.readline
def N(): return int(input())
def NM():return map(int,input().split())
def L():return list(NM())
def LN(n):return [N() for i in range(n)]
def LL(n):return [L() for i in range(n)]
n,k=NM()
l=L()
ans=0
for a in range(n+1):
    for b in range(n-a+1):
        for c in range(a+1):
            for d in range(b+1):
                if a+b+c+d>k:
                    continue
                x=l[:a]
                y=l[-1:-b-1:-1]
                x.sort()
                y.sort()
                ans=max(ans,sum(x[c:])+sum(y[d:]))
print(ans)