import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

ans=0
for i in range(k+1):
    toru=i
    ireru=k-i
    # print(toru)
    for j in range(toru+1):
        l,r=j,n-(toru-j)
        if l>r:
            lst=v[:]
        else:
            lst=v[:l]+v[r:]
        # print(lst)
        lst.sort(reverse=True)
        for l in range(ireru):
            if lst and lst[-1]<0:
                lst.pop()
        ans=max(ans,sum(lst))

print(ans) import bisect, copy, heapq, math, sys bisect copy heapq math sys from collections import * from functools import lru_cache from itertools import accumulate, combinations, permutations, product def input():
    return sys.stdin.readline()[:-1] input return sys.stdin.readline()[:-1] sys.stdin.readline()[:-1] sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline :-1 -1 def ruiseki(lst):
    return [0]+list(accumulate(lst)) ruiseki return [0]+list(accumulate(lst)) [0]+list(accumulate(lst)) [0] 0 list(accumulate(lst)) list accumulate(lst) accumulate lst lst lst def celi(a,b):
    return -(-a//b) celi return -(-a//b) -(-a//b) -a//b -a a b a a b b sys.setrecursionlimit(5000000) sys.setrecursionlimit sys setrecursionlimit 5000000 mod=pow(10,9)+7 mod pow(10,9)+7 pow(10,9) pow 10 9 7 chr(ord('a') + i) for i in range(26) for i in range(26) i range(26) range 26 for i in range(26) chr(ord('a') + i) chr ord('a') + i ord('a') ord 'a' i al=[chr(ord('a') + i) for i in range(26)] al [chr(ord('a') + i) for i in range(26)] direction=[[1,0],[0,1],[-1,0],[0,-1]] direction [[1,0],[0,1],[-1,0],[0,-1]] [1,0] 1 0 [0,1] 0 1 [-1,0] -1 0 [0,-1] 0 -1 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 i in range(k+1):
    toru=i
    ireru=k-i
    # print(toru)
    for j in range(toru+1):
        l,r=j,n-(toru-j)
        if l>r:
            lst=v[:]
        else:
            lst=v[:l]+v[r:]
        # print(lst)
        lst.sort(reverse=True)
        for l in range(ireru):
            if lst and lst[-1]<0:
                lst.pop()
        ans=max(ans,sum(lst)) i range(k+1) range k+1 k 1 toru=i toru i ireru=k-i ireru k-i k i for j in range(toru+1):
        l,r=j,n-(toru-j)
        if l>r:
            lst=v[:]
        else:
            lst=v[:l]+v[r:]
        # print(lst)
        lst.sort(reverse=True)
        for l in range(ireru):
            if lst and lst[-1]<0:
                lst.pop()
        ans=max(ans,sum(lst)) j range(toru+1) range toru+1 toru 1 l,r=j,n-(toru-j) l j r n-(toru-j) n toru-j toru j if l>r:
            lst=v[:]
        else:
            lst=v[:l]+v[r:]
        # print(lst)
         l>r l r lst=v[:] lst v[:] v : lst=v[:l]+v[r:] lst v[:l]+v[r:] v[:l] v :l l v[r:] v r: r lst.sort(reverse=True) lst.sort lst sort reverse=True reverse True for l in range(ireru):
            if lst and lst[-1]<0:
                lst.pop()
         l range(ireru) range ireru if lst and lst[-1]<0:
                lst.pop()
         lst and lst[-1]<0 lst lst[-1]<0 lst[-1] lst -1 0 lst.pop() lst.pop lst pop ans=max(ans,sum(lst)) ans max(ans,sum(lst)) max ans sum(lst) sum lst print(ans) print ans ans=0 0 ans ireru=k-i k-i ireru lst=v[:l]+v[r:] v[:l]+v[r:] lst n,k=map(int,input().split()) map(int,input().split()) n r=j,n-(toru-j) n-(toru-j) r al=[chr(ord('a') + i) for i in range(26)] [chr(ord('a') + i) for i in range(26)] al toru=i i toru def input():
    return sys.stdin.readline()[:-1] def input():
    return sys.stdin.readline()[:-1] input mod=pow(10,9)+7 pow(10,9)+7 mod k=map(int,input().split()) map(int,input().split()) k def ruiseki(lst):
    return [0]+list(accumulate(lst)) def ruiseki(lst):
    return [0]+list(accumulate(lst)) ruiseki l,r=j,n-(toru-j) j l v=list(map(int,input().split())) list(map(int,input().split())) v ans=max(ans,sum(lst)) max(ans,sum(lst)) ans lst=v[:] v[:] lst direction=[[1,0],[0,1],[-1,0],[0,-1]] [[1,0],[0,1],[-1,0],[0,-1]] direction def celi(a,b):
    return -(-a//b) def celi(a,b):
    return -(-a//b) celi
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

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

ans=0
for i in range(k+1):
    toru=i
    ireru=k-i
    # print(toru)
    for j in range(toru+1):
        l,r=j,n-(toru-j)
        if l>r:
            lst=v[:]
        else:
            lst=v[:l]+v[r:]
        # print(lst)
        lst.sort(reverse=True)
        for l in range(ireru):
            if lst and lst[-1]<0:
                lst.pop()
        ans=max(ans,sum(lst))

print(ans)