N,K = map(int,input().split())
V = [0] + list(map(int,input().split())) + [0]
m = min(N,K)

A = []
ans = 0

#左からi個、右からj個除いた時の宝石の価値のmax

for i in range(m+1):
    if i == 0:
        pass
    else:
        A.append(V[i])
    B = []
    for j in range(m-i+1):
        if j == 0:
            pass
        else:
            B.append(V[N-j+1])
        C = A+B
        C.sort()
        a = sum(C)
        for k in range(len(C)):
            if C[k] < 0 and k < K-(i+j):
                a -= C[k]
        ans = max(ans,a)

print(ans) N,K = map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split K V = [0] + list(map(int,input().split())) + [0] V [0] + list(map(int,input().split())) + [0] [0] + list(map(int,input().split())) [0] 0 list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split [0] 0 m = min(N,K) m min(N,K) min N K A = [] A [] ans = 0 ans 0 for i in range(m+1):
    if i == 0:
        pass
    else:
        A.append(V[i])
    B = []
    for j in range(m-i+1):
        if j == 0:
            pass
        else:
            B.append(V[N-j+1])
        C = A+B
        C.sort()
        a = sum(C)
        for k in range(len(C)):
            if C[k] < 0 and k < K-(i+j):
                a -= C[k]
        ans = max(ans,a) i range(m+1) range m+1 m 1 if i == 0:
        pass
    else:
        A.append(V[i])
     i == 0 i 0 A.append(V[i]) A.append A append V[i] V i B = [] B [] for j in range(m-i+1):
        if j == 0:
            pass
        else:
            B.append(V[N-j+1])
        C = A+B
        C.sort()
        a = sum(C)
        for k in range(len(C)):
            if C[k] < 0 and k < K-(i+j):
                a -= C[k]
        ans = max(ans,a) j range(m-i+1) range m-i+1 m-i m i 1 if j == 0:
            pass
        else:
            B.append(V[N-j+1])
         j == 0 j 0 B.append(V[N-j+1]) B.append B append V[N-j+1] V N-j+1 N-j N j 1 C = A+B C A+B A B C.sort() C.sort C sort a = sum(C) a sum(C) sum C for k in range(len(C)):
            if C[k] < 0 and k < K-(i+j):
                a -= C[k]
         k range(len(C)) range len(C) len C if C[k] < 0 and k < K-(i+j):
                a -= C[k]
         C[k] < 0 and k < K-(i+j) C[k] < 0 C[k] C k 0 k < K-(i+j) k K-(i+j) K i+j i j a -= C[k] a C[k] C k ans = max(ans,a) ans max(ans,a) max ans a print(ans) print ans m = min(N,K) min(N,K) m V = [0] + list(map(int,input().split())) + [0] [0] + list(map(int,input().split())) + [0] V a = sum(C) sum(C) a ans = max(ans,a) max(ans,a) ans a -= C[k] C[k] a ans = 0 0 ans A = [] [] A B = [] [] B C = A+B A+B C K = map(int,input().split()) map(int,input().split()) K N,K = map(int,input().split()) map(int,input().split()) N
N,K = map(int,input().split())
V = [0] + list(map(int,input().split())) + [0]
m = min(N,K)

A = []
ans = 0

#左からi個、右からj個除いた時の宝石の価値のmax

for i in range(m+1):
    if i == 0:
        pass
    else:
        A.append(V[i])
    B = []
    for j in range(m-i+1):
        if j == 0:
            pass
        else:
            B.append(V[N-j+1])
        C = A+B
        C.sort()
        a = sum(C)
        for k in range(len(C)):
            if C[k] < 0 and k < K-(i+j):
                a -= C[k]
        ans = max(ans,a)

print(ans)