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

result=0

for a in range(min(n,k)+1):
    for b in range(min(n,k)+1-a):
        tmp=v[:a]+v[n-b:]
        tmp.sort()

        lost=k-a-b

        ttt=[]
        cnt=0
        for item in tmp:
            if item<0 and cnt<lost:
                ttt.append(item)
                cnt+=1
            else:
                break
        result=max(result,sum(tmp)-sum(ttt))

print(result)
 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 result=0 result 0 for a in range(min(n,k)+1):
    for b in range(min(n,k)+1-a):
        tmp=v[:a]+v[n-b:]
        tmp.sort()

        lost=k-a-b

        ttt=[]
        cnt=0
        for item in tmp:
            if item<0 and cnt<lost:
                ttt.append(item)
                cnt+=1
            else:
                break
        result=max(result,sum(tmp)-sum(ttt)) a range(min(n,k)+1) range min(n,k)+1 min(n,k) min n k 1 for b in range(min(n,k)+1-a):
        tmp=v[:a]+v[n-b:]
        tmp.sort()

        lost=k-a-b

        ttt=[]
        cnt=0
        for item in tmp:
            if item<0 and cnt<lost:
                ttt.append(item)
                cnt+=1
            else:
                break
        result=max(result,sum(tmp)-sum(ttt)) b range(min(n,k)+1-a) range min(n,k)+1-a min(n,k)+1 min(n,k) min n k 1 a tmp=v[:a]+v[n-b:] tmp v[:a]+v[n-b:] v[:a] v :a a v[n-b:] v n-b: n-b n b tmp.sort() tmp.sort tmp sort lost=k-a-b lost k-a-b k-a k a b ttt=[] ttt [] cnt=0 cnt 0 for item in tmp:
            if item<0 and cnt<lost:
                ttt.append(item)
                cnt+=1
            else:
                break
         item tmp if item<0 and cnt<lost:
                ttt.append(item)
                cnt+=1
            else:
                break
         item<0 and cnt<lost item<0 item 0 cnt<lost cnt lost ttt.append(item) ttt.append ttt append item cnt+=1 cnt 1 break result=max(result,sum(tmp)-sum(ttt)) result max(result,sum(tmp)-sum(ttt)) max result sum(tmp)-sum(ttt) sum(tmp) sum tmp sum(ttt) sum ttt print(result) print result lost=k-a-b k-a-b lost n,k=map(int,input().split()) map(int,input().split()) n cnt=0 0 cnt result=0 0 result k=map(int,input().split()) map(int,input().split()) k cnt+=1 1 cnt result=max(result,sum(tmp)-sum(ttt)) max(result,sum(tmp)-sum(ttt)) result v=list(map(int,input().split())) list(map(int,input().split())) v ttt=[] [] ttt tmp=v[:a]+v[n-b:] v[:a]+v[n-b:] tmp
n,k=map(int,input().split())
v=list(map(int,input().split()))

result=0

for a in range(min(n,k)+1):
    for b in range(min(n,k)+1-a):
        tmp=v[:a]+v[n-b:]
        tmp.sort()

        lost=k-a-b

        ttt=[]
        cnt=0
        for item in tmp:
            if item<0 and cnt<lost:
                ttt.append(item)
                cnt+=1
            else:
                break
        result=max(result,sum(tmp)-sum(ttt))

print(result)

