import sys
input = sys.stdin.readline
N,K = map(int,input().split())
V = list(map(int,input().split()))

D = []
ans = []

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==[]:
        ans.append(0)
    elif sum(d)>0:
        ans.append(sum(d))

if max(ans)>0:
    print(max(ans))

else:
    print(0) 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 = [] ans [] 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==[]:
        ans.append(0)
    elif sum(d)>0:
        ans.append(sum(d)) 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==[]:
        ans.append(0)
    elif sum(d)>0:
        ans.append(sum(d)) d==[] d [] ans.append(0) ans.append ans append 0 elif sum(d)>0:
        ans.append(sum(d)) sum(d)>0 sum(d) sum d 0 ans.append(sum(d)) ans.append ans append sum(d) sum d if max(ans)>0:
    print(max(ans))

else:
    print(0) max(ans)>0 max(ans) max ans 0 print(max(ans)) print max(ans) max ans print(0) print 0 N,K = map(int,input().split()) map(int,input().split()) N V = list(map(int,input().split())) list(map(int,input().split())) V input = sys.stdin.readline sys.stdin.readline input K = map(int,input().split()) map(int,input().split()) K ans = [] [] ans D = [] [] D
import sys
input = sys.stdin.readline
N,K = map(int,input().split())
V = list(map(int,input().split()))

D = []
ans = []

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==[]:
        ans.append(0)
    elif sum(d)>0:
        ans.append(sum(d))

if max(ans)>0:
    print(max(ans))

else:
    print(0)