N,K = map(int,input().split())
V = list(map(int,input().split()))
Vrev = V[::-1]
ans = 0
for a in range(N+1):
    for b in range(min(K-a,N-a)+1):
        VV = V[:a] + Vrev[:b]
        VV.sort(reverse=True)
        for k in range(min(K-a-b,len(VV))):
            if VV[-1] < 0:
                VV.pop()
        ans = max(sum(VV),ans)
print(ans) 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 Vrev = V[::-1] Vrev V[::-1] V ::-1 -1 ans = 0 ans 0 for a in range(N+1):
    for b in range(min(K-a,N-a)+1):
        VV = V[:a] + Vrev[:b]
        VV.sort(reverse=True)
        for k in range(min(K-a-b,len(VV))):
            if VV[-1] < 0:
                VV.pop()
        ans = max(sum(VV),ans) a range(N+1) range N+1 N 1 for b in range(min(K-a,N-a)+1):
        VV = V[:a] + Vrev[:b]
        VV.sort(reverse=True)
        for k in range(min(K-a-b,len(VV))):
            if VV[-1] < 0:
                VV.pop()
        ans = max(sum(VV),ans) b range(min(K-a,N-a)+1) range min(K-a,N-a)+1 min(K-a,N-a) min K-a K a N-a N a 1 VV = V[:a] + Vrev[:b] VV V[:a] + Vrev[:b] V[:a] V :a a Vrev[:b] Vrev :b b VV.sort(reverse=True) VV.sort VV sort reverse=True reverse True for k in range(min(K-a-b,len(VV))):
            if VV[-1] < 0:
                VV.pop()
         k range(min(K-a-b,len(VV))) range min(K-a-b,len(VV)) min K-a-b K-a K a b len(VV) len VV if VV[-1] < 0:
                VV.pop()
         VV[-1] < 0 VV[-1] VV -1 0 VV.pop() VV.pop VV pop ans = max(sum(VV),ans) ans max(sum(VV),ans) max sum(VV) sum VV ans print(ans) print ans ans = 0 0 ans VV = V[:a] + Vrev[:b] V[:a] + Vrev[:b] VV V = list(map(int,input().split())) list(map(int,input().split())) V K = map(int,input().split()) map(int,input().split()) K Vrev = V[::-1] V[::-1] Vrev ans = max(sum(VV),ans) max(sum(VV),ans) ans N,K = map(int,input().split()) map(int,input().split()) N
N,K = map(int,input().split())
V = list(map(int,input().split()))
Vrev = V[::-1]
ans = 0
for a in range(N+1):
    for b in range(min(K-a,N-a)+1):
        VV = V[:a] + Vrev[:b]
        VV.sort(reverse=True)
        for k in range(min(K-a-b,len(VV))):
            if VV[-1] < 0:
                VV.pop()
        ans = max(sum(VV),ans)
print(ans)
