import sys
input = sys.stdin.readline
N,K = map(int,input().split())
V = list(map(int,input().split()))
D = []
ans = 0
for i in range(K+1):
    for j in range(K-i+1):
        if i + j > N:
            break
        D.append(V[:i]+V[N-j:])
for d in D:
    for x in range(K-len(d)):
        if d==[]:
            break
        elif min(d)<0:
            d.pop(d.index(min(d)))

        elif min(d)>0:
            break        
    if d!=[]:
        s = sum(d)
        if s>0 and s>ans:
            ans = s
print(ans) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline 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 D = [] D [] ans = 0 ans 0 for i in range(K+1):
    for j in range(K-i+1):
        if i + j > N:
            break
        D.append(V[:i]+V[N-j:]) i range(K+1) range K+1 K 1 for j in range(K-i+1):
        if i + j > N:
            break
        D.append(V[:i]+V[N-j:]) j range(K-i+1) range K-i+1 K-i K i 1 if i + j > N:
            break
         i + j > N i + j i j N break D.append(V[:i]+V[N-j:]) D.append D append V[:i]+V[N-j:] V[:i] V :i i V[N-j:] V N-j: N-j N j for d in D:
    for x in range(K-len(d)):
        if d==[]:
            break
        elif min(d)<0:
            d.pop(d.index(min(d)))

        elif min(d)>0:
            break        
    if d!=[]:
        s = sum(d)
        if s>0 and s>ans:
            ans = s d D for x in range(K-len(d)):
        if d==[]:
            break
        elif min(d)<0:
            d.pop(d.index(min(d)))

        elif min(d)>0:
            break        
     x range(K-len(d)) range K-len(d) K len(d) len d if d==[]:
            break
        elif min(d)<0:
            d.pop(d.index(min(d)))

        elif min(d)>0:
            break        
     d==[] d [] break elif min(d)<0:
            d.pop(d.index(min(d)))

         min(d)<0 min(d) min d 0 d.pop(d.index(min(d))) d.pop d pop d.index(min(d)) d.index d index min(d) min d elif min(d)>0:
            break        
     min(d)>0 min(d) min d 0 break if d!=[]:
        s = sum(d)
        if s>0 and s>ans:
            ans = s d!=[] d [] s = sum(d) s sum(d) sum d if s>0 and s>ans:
            ans = s s>0 and s>ans s>0 s 0 s>ans s ans ans = s ans s print(ans) print ans s = sum(d) sum(d) s D = [] [] D K = map(int,input().split()) map(int,input().split()) K ans = 0 0 ans V = list(map(int,input().split())) list(map(int,input().split())) V input = sys.stdin.readline sys.stdin.readline input N,K = map(int,input().split()) map(int,input().split()) N ans = s s ans
import sys
input = sys.stdin.readline
N,K = map(int,input().split())
V = list(map(int,input().split()))
D = []
ans = 0
for i in range(K+1):
    for j in range(K-i+1):
        if i + j > N:
            break
        D.append(V[:i]+V[N-j:])
for d in D:
    for x in range(K-len(d)):
        if d==[]:
            break
        elif min(d)<0:
            d.pop(d.index(min(d)))

        elif min(d)>0:
            break        
    if d!=[]:
        s = sum(d)
        if s>0 and s>ans:
            ans = s
print(ans)