# coding: utf-8
# Your code here!

n,k=map(int,input().split())
v=list(map(int,input().split()))
ans=0

for a in range(n+1):
    for b in range(n+1):
        if a+b>n:
            break
        if a+b>k:
            break
        if a+b==n:
            val=sum(v)
            ans=max(ans,val)
            # print(a,b,val)
            continue
        tmp=v[:a]+v[::-1][:b]
        val=sum(tmp)
        c=k-a-b
        tmp.sort()
        for i in range(min(c,a+b)):
            if tmp[i]<0:
                val-=tmp[i]
            else:
                break
        ans=max(ans,val)
        # print(a,b,val)
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 ans=0 ans 0 for a in range(n+1):
    for b in range(n+1):
        if a+b>n:
            break
        if a+b>k:
            break
        if a+b==n:
            val=sum(v)
            ans=max(ans,val)
            # print(a,b,val)
            continue
        tmp=v[:a]+v[::-1][:b]
        val=sum(tmp)
        c=k-a-b
        tmp.sort()
        for i in range(min(c,a+b)):
            if tmp[i]<0:
                val-=tmp[i]
            else:
                break
        ans=max(ans,val)
        # print(a,b,val) a range(n+1) range n+1 n 1 for b in range(n+1):
        if a+b>n:
            break
        if a+b>k:
            break
        if a+b==n:
            val=sum(v)
            ans=max(ans,val)
            # print(a,b,val)
            continue
        tmp=v[:a]+v[::-1][:b]
        val=sum(tmp)
        c=k-a-b
        tmp.sort()
        for i in range(min(c,a+b)):
            if tmp[i]<0:
                val-=tmp[i]
            else:
                break
        ans=max(ans,val)
        # print(a,b,val) b range(n+1) range n+1 n 1 if a+b>n:
            break
         a+b>n a+b a b n break if a+b>k:
            break
         a+b>k a+b a b k break if a+b==n:
            val=sum(v)
            ans=max(ans,val)
            # print(a,b,val)
            continue
         a+b==n a+b a b n val=sum(v) val sum(v) sum v ans=max(ans,val) ans max(ans,val) max ans val continue tmp=v[:a]+v[::-1][:b] tmp v[:a]+v[::-1][:b] v[:a] v :a a v[::-1][:b] [::-1] v ::-1 -1 :b b val=sum(tmp) val sum(tmp) sum tmp c=k-a-b c k-a-b k-a k a b tmp.sort() tmp.sort tmp sort for i in range(min(c,a+b)):
            if tmp[i]<0:
                val-=tmp[i]
            else:
                break
         i range(min(c,a+b)) range min(c,a+b) min c a+b a b if tmp[i]<0:
                val-=tmp[i]
            else:
                break
         tmp[i]<0 tmp[i] tmp i 0 val-=tmp[i] val tmp[i] tmp i break ans=max(ans,val) ans max(ans,val) max ans val print(ans) print ans ans=max(ans,val) max(ans,val) ans val=sum(tmp) sum(tmp) val tmp=v[:a]+v[::-1][:b] v[:a]+v[::-1][:b] tmp v=list(map(int,input().split())) list(map(int,input().split())) v ans=0 0 ans val=sum(v) sum(v) val ans=max(ans,val) max(ans,val) ans n,k=map(int,input().split()) map(int,input().split()) n k=map(int,input().split()) map(int,input().split()) k c=k-a-b k-a-b c val-=tmp[i] tmp[i] val
# coding: utf-8
# Your code here!

n,k=map(int,input().split())
v=list(map(int,input().split()))
ans=0

for a in range(n+1):
    for b in range(n+1):
        if a+b>n:
            break
        if a+b>k:
            break
        if a+b==n:
            val=sum(v)
            ans=max(ans,val)
            # print(a,b,val)
            continue
        tmp=v[:a]+v[::-1][:b]
        val=sum(tmp)
        c=k-a-b
        tmp.sort()
        for i in range(min(c,a+b)):
            if tmp[i]<0:
                val-=tmp[i]
            else:
                break
        ans=max(ans,val)
        # print(a,b,val)
print(ans)
