import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    #N = int(input())
    N, K = map(int, input().split())
    #
    vs = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    ans=0
    ls=0
    dlis1=[]
    for l in range(min(N,K)+1):
        rs=0
        dlis2=[]
        if l>=1:
            tag=vs[l-1]
            ls+=tag
            if tag<0:
                dlis1.append(tag)
        for r in range(min(K-l,N)+1):
            if r>=1:
                tag=vs[-1-r+1]
                rs+=tag
                if tag<0:
                    dlis2.append(tag)
            dlis=dlis1+dlis2
            dlis.sort()
            td=0
            
            dec =min(K-l-r,len(dlis))
            if dec>=1:
                td=sum(dlis[:dec])
            tot=ls+rs-td
            #printe(l,ls,r,rs,dec,td)
            ans=max(ans,tot)

            if l+r>=N:
                break

    print(ans)

if __name__ == "__main__":
    main() import sys sys sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 import math math from copy import copy, deepcopy from copy import deepcopy as dcp from operator import itemgetter from bisect import bisect_left, bisect, bisect_right from collections import deque, defaultdict from collections import Counter from itertools import accumulate,combinations,permutations from heapq import heapify,heappop,heappush from functools import reduce,lru_cache from decimal import Decimal def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x input x=sys.stdin.readline() x sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline return x[:-1] if x[-1]=="\n" else x x[:-1] if x[-1]=="\n" else x x[-1]=="\n" x[-1] x -1 "\n" x[:-1] x :-1 -1 x def printe(*x):print("## ",*x,file=sys.stderr) printe *x def printl(li): _=print(*li, sep="\n") if li else None printl li li def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds argsort inds=sorted(range(len(s)), key=lambda k: s[k]) inds sorted(range(len(s)), key=lambda k: s[k]) sorted range(len(s)) range len(s) len s key=lambda k: s[k] key lambda k: s[k] s[k] s k k s[i] for i in inds for i in inds i inds for i in inds s[i] s i if return_sorted: return inds, [s[i] for i in inds]
     return_sorted return inds inds s s return_sorted=False return_sorted False def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65 alp2num c c cap=False cap False def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65) num2alp i i cap=False cap False def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)] matmat K,N,M=len(B),len(A),len(B[0]) K len(B) len B N len(A) len A M len(B[0]) len B[0] B 0 [sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N) for i in range(N) i range(N) range N for i in range(N) [sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)] [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)] A A B B def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)] matvec N,size=len(v),len(M) N len(v) len v size len(M) len M sum([M[i][j]*v[j] for j in range(N)]) for i in range(size) for i in range(size) i range(size) range size for i in range(size) sum([M[i][j]*v[j] for j in range(N)]) sum [M[i][j]*v[j] for j in range(N)] return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)] [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)] M M v v def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)] T n,m=len(M),len(M[0]) n len(M) len M m len(M[0]) len M[0] M 0 [M[j][i] for j in range(n)] for i in range(m) for i in range(m) i range(m) range m for i in range(m) [M[j][i] for j in range(n)] return [[M[j][i] for j in range(n)] for i in range(m)] [[M[j][i] for j in range(n)] for i in range(m)] M M def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    #N = int(input())
    N, K = map(int, input().split())
    #
    vs = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    ans=0
    ls=0
    dlis1=[]
    for l in range(min(N,K)+1):
        rs=0
        dlis2=[]
        if l>=1:
            tag=vs[l-1]
            ls+=tag
            if tag<0:
                dlis1.append(tag)
        for r in range(min(K-l,N)+1):
            if r>=1:
                tag=vs[-1-r+1]
                rs+=tag
                if tag<0:
                    dlis2.append(tag)
            dlis=dlis1+dlis2
            dlis.sort()
            td=0
            
            dec =min(K-l-r,len(dlis))
            if dec>=1:
                td=sum(dlis[:dec])
            tot=ls+rs-td
            #printe(l,ls,r,rs,dec,td)
            ans=max(ans,tot)

            if l+r>=N:
                break

    print(ans) main mod = 1000000007 mod 1000000007 N, K = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split K vs = tuple(map(int, input().split())) vs tuple(map(int, input().split())) tuple map(int, input().split()) map int input().split() ().split () input split ans=0 ans 0 ls=0 ls 0 dlis1=[] dlis1 [] for l in range(min(N,K)+1):
        rs=0
        dlis2=[]
        if l>=1:
            tag=vs[l-1]
            ls+=tag
            if tag<0:
                dlis1.append(tag)
        for r in range(min(K-l,N)+1):
            if r>=1:
                tag=vs[-1-r+1]
                rs+=tag
                if tag<0:
                    dlis2.append(tag)
            dlis=dlis1+dlis2
            dlis.sort()
            td=0
            
            dec =min(K-l-r,len(dlis))
            if dec>=1:
                td=sum(dlis[:dec])
            tot=ls+rs-td
            #printe(l,ls,r,rs,dec,td)
            ans=max(ans,tot)

            if l+r>=N:
                break

     l range(min(N,K)+1) range min(N,K)+1 min(N,K) min N K 1 rs=0 rs 0 dlis2=[] dlis2 [] if l>=1:
            tag=vs[l-1]
            ls+=tag
            if tag<0:
                dlis1.append(tag)
         l>=1 l 1 tag=vs[l-1] tag vs[l-1] vs l-1 l 1 ls+=tag ls tag if tag<0:
                dlis1.append(tag)
         tag<0 tag 0 dlis1.append(tag) dlis1.append dlis1 append tag for r in range(min(K-l,N)+1):
            if r>=1:
                tag=vs[-1-r+1]
                rs+=tag
                if tag<0:
                    dlis2.append(tag)
            dlis=dlis1+dlis2
            dlis.sort()
            td=0
            
            dec =min(K-l-r,len(dlis))
            if dec>=1:
                td=sum(dlis[:dec])
            tot=ls+rs-td
            #printe(l,ls,r,rs,dec,td)
            ans=max(ans,tot)

            if l+r>=N:
                break

     r range(min(K-l,N)+1) range min(K-l,N)+1 min(K-l,N) min K-l K l N 1 if r>=1:
                tag=vs[-1-r+1]
                rs+=tag
                if tag<0:
                    dlis2.append(tag)
             r>=1 r 1 tag=vs[-1-r+1] tag vs[-1-r+1] vs -1-r+1 -1-r -1 r 1 rs+=tag rs tag if tag<0:
                    dlis2.append(tag)
             tag<0 tag 0 dlis2.append(tag) dlis2.append dlis2 append tag dlis=dlis1+dlis2 dlis dlis1+dlis2 dlis1 dlis2 dlis.sort() dlis.sort dlis sort td=0 td 0 dec =min(K-l-r,len(dlis)) dec min(K-l-r,len(dlis)) min K-l-r K-l K l r len(dlis) len dlis if dec>=1:
                td=sum(dlis[:dec])
             dec>=1 dec 1 td=sum(dlis[:dec]) td sum(dlis[:dec]) sum dlis[:dec] dlis :dec dec tot=ls+rs-td tot ls+rs-td ls+rs ls rs td ans=max(ans,tot) ans max(ans,tot) max ans tot if l+r>=N:
                break

     l+r>=N l+r l r N break print(ans) print ans if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds argsort def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    #N = int(input())
    N, K = map(int, input().split())
    #
    vs = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    ans=0
    ls=0
    dlis1=[]
    for l in range(min(N,K)+1):
        rs=0
        dlis2=[]
        if l>=1:
            tag=vs[l-1]
            ls+=tag
            if tag<0:
                dlis1.append(tag)
        for r in range(min(K-l,N)+1):
            if r>=1:
                tag=vs[-1-r+1]
                rs+=tag
                if tag<0:
                    dlis2.append(tag)
            dlis=dlis1+dlis2
            dlis.sort()
            td=0
            
            dec =min(K-l-r,len(dlis))
            if dec>=1:
                td=sum(dlis[:dec])
            tot=ls+rs-td
            #printe(l,ls,r,rs,dec,td)
            ans=max(ans,tot)

            if l+r>=N:
                break

    print(ans) def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    #N = int(input())
    N, K = map(int, input().split())
    #
    vs = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    ans=0
    ls=0
    dlis1=[]
    for l in range(min(N,K)+1):
        rs=0
        dlis2=[]
        if l>=1:
            tag=vs[l-1]
            ls+=tag
            if tag<0:
                dlis1.append(tag)
        for r in range(min(K-l,N)+1):
            if r>=1:
                tag=vs[-1-r+1]
                rs+=tag
                if tag<0:
                    dlis2.append(tag)
            dlis=dlis1+dlis2
            dlis.sort()
            td=0
            
            dec =min(K-l-r,len(dlis))
            if dec>=1:
                td=sum(dlis[:dec])
            tot=ls+rs-td
            #printe(l,ls,r,rs,dec,td)
            ans=max(ans,tot)

            if l+r>=N:
                break

    print(ans) main def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65 def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65 alp2num def printl(li): _=print(*li, sep="\n") if li else None def printl(li): _=print(*li, sep="\n") if li else None printl def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65) def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65) num2alp def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)] def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)] matvec def printe(*x):print("## ",*x,file=sys.stderr) def printe(*x):print("## ",*x,file=sys.stderr) printe def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)] def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)] T def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x input def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)] def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)] matmat
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from copy import deepcopy as dcp
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque, defaultdict
#deque(l), pop(), append(x), popleft(), appendleft(x)
#q.rotate(n)で → にn回ローテート
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate,combinations,permutations#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import reduce,lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率
from decimal import Decimal

def input(): 
    x=sys.stdin.readline()
    return x[:-1] if x[-1]=="\n" else x
def printe(*x):print("## ",*x,file=sys.stderr)
def printl(li): _=print(*li, sep="\n") if li else None
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 1000000007
    #w.sort(key=itemgetter(1),reverse=True)  #二個目の要素で降順並び替え

    #N = int(input())
    N, K = map(int, input().split())
    #
    vs = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    ans=0
    ls=0
    dlis1=[]
    for l in range(min(N,K)+1):
        rs=0
        dlis2=[]
        if l>=1:
            tag=vs[l-1]
            ls+=tag
            if tag<0:
                dlis1.append(tag)
        for r in range(min(K-l,N)+1):
            if r>=1:
                tag=vs[-1-r+1]
                rs+=tag
                if tag<0:
                    dlis2.append(tag)
            dlis=dlis1+dlis2
            dlis.sort()
            td=0
            
            dec =min(K-l-r,len(dlis))
            if dec>=1:
                td=sum(dlis[:dec])
            tot=ls+rs-td
            #printe(l,ls,r,rs,dec,td)
            ans=max(ans,tot)

            if l+r>=N:
                break

    print(ans)

if __name__ == "__main__":
    main()