N,K = map(int,input().split())
V = list(map(int,input().split()))
vmax = -10**9
for n1 in range(K+1):
    A = V[:n1]
    ind = min(n1,N)
    m = N-ind
    for n2 in range(min(K-n1,m)+1):
        B = V[N-n2:]
        C = A+B
        C = sorted(C,reverse=True)
        k = K-n1-n2
        for i in range(k):
            if len(C)==0 or C[-1]>=0:break
            C.pop()
        vmax = max(vmax,sum(C))
print(vmax)            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 vmax = -10**9 vmax -10**9 -10 9 for n1 in range(K+1):
    A = V[:n1]
    ind = min(n1,N)
    m = N-ind
    for n2 in range(min(K-n1,m)+1):
        B = V[N-n2:]
        C = A+B
        C = sorted(C,reverse=True)
        k = K-n1-n2
        for i in range(k):
            if len(C)==0 or C[-1]>=0:break
            C.pop()
        vmax = max(vmax,sum(C)) n1 range(K+1) range K+1 K 1 A = V[:n1] A V[:n1] V :n1 n1 ind = min(n1,N) ind min(n1,N) min n1 N m = N-ind m N-ind N ind for n2 in range(min(K-n1,m)+1):
        B = V[N-n2:]
        C = A+B
        C = sorted(C,reverse=True)
        k = K-n1-n2
        for i in range(k):
            if len(C)==0 or C[-1]>=0:break
            C.pop()
        vmax = max(vmax,sum(C)) n2 range(min(K-n1,m)+1) range min(K-n1,m)+1 min(K-n1,m) min K-n1 K n1 m 1 B = V[N-n2:] B V[N-n2:] V N-n2: N-n2 N n2 C = A+B C A+B A B C = sorted(C,reverse=True) C sorted(C,reverse=True) sorted C reverse=True reverse True k = K-n1-n2 k K-n1-n2 K-n1 K n1 n2 for i in range(k):
            if len(C)==0 or C[-1]>=0:break
            C.pop()
         i range(k) range k if len(C)==0 or C[-1]>=0:break
             len(C)==0 or C[-1]>=0 len(C)==0 len(C) len C 0 C[-1]>=0 C[-1] C -1 0 C.pop() C.pop C pop vmax = max(vmax,sum(C)) vmax max(vmax,sum(C)) max vmax sum(C) sum C print(vmax) print vmax K = map(int,input().split()) map(int,input().split()) K vmax = -10**9 -10**9 vmax B = V[N-n2:] V[N-n2:] B m = N-ind N-ind m k = K-n1-n2 K-n1-n2 k V = list(map(int,input().split())) list(map(int,input().split())) V N,K = map(int,input().split()) map(int,input().split()) N vmax = max(vmax,sum(C)) max(vmax,sum(C)) vmax ind = min(n1,N) min(n1,N) ind A = V[:n1] V[:n1] A C = sorted(C,reverse=True) sorted(C,reverse=True) C C = A+B A+B C
N,K = map(int,input().split())
V = list(map(int,input().split()))
vmax = -10**9
for n1 in range(K+1):
    A = V[:n1]
    ind = min(n1,N)
    m = N-ind
    for n2 in range(min(K-n1,m)+1):
        B = V[N-n2:]
        C = A+B
        C = sorted(C,reverse=True)
        k = K-n1-n2
        for i in range(k):
            if len(C)==0 or C[-1]>=0:break
            C.pop()
        vmax = max(vmax,sum(C))
print(vmax)           