N, K = map(int,input().split())
V = list(map(int,input().split()))

ans = 0

for a in range(min(N,K)+1):
    for b in range(min(N,K)-a+1):
        cur = V[:a] + V[N-b:]
        cur.sort()

        idx = 0
        while idx < min(K-a-b, len(cur)):
            if cur[idx] > 0: break
            else: idx += 1
        
        ans = max(ans, sum(cur[idx:]))
    
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 ans = 0 ans 0 for a in range(min(N,K)+1):
    for b in range(min(N,K)-a+1):
        cur = V[:a] + V[N-b:]
        cur.sort()

        idx = 0
        while idx < min(K-a-b, len(cur)):
            if cur[idx] > 0: break
            else: idx += 1
        
        ans = max(ans, sum(cur[idx:]))
     a range(min(N,K)+1) range min(N,K)+1 min(N,K) min N K 1 for b in range(min(N,K)-a+1):
        cur = V[:a] + V[N-b:]
        cur.sort()

        idx = 0
        while idx < min(K-a-b, len(cur)):
            if cur[idx] > 0: break
            else: idx += 1
        
        ans = max(ans, sum(cur[idx:]))
     b range(min(N,K)-a+1) range min(N,K)-a+1 min(N,K)-a min(N,K) min N K a 1 cur = V[:a] + V[N-b:] cur V[:a] + V[N-b:] V[:a] V :a a V[N-b:] V N-b: N-b N b cur.sort() cur.sort cur sort idx = 0 idx 0 while idx < min(K-a-b, len(cur)):
            if cur[idx] > 0: break
            else: idx += 1
        
         idx < min(K-a-b, len(cur)) idx min(K-a-b, len(cur)) min K-a-b K-a K a b len(cur) len cur if cur[idx] > 0: break
            else: idx += 1
        
         cur[idx] > 0 cur[idx] cur idx 0 ans = max(ans, sum(cur[idx:])) ans max(ans, sum(cur[idx:])) max ans sum(cur[idx:]) sum cur[idx:] cur idx: idx print(ans) print ans K = map(int,input().split()) map(int,input().split()) K ans = 0 0 ans idx = 0 0 idx N, K = map(int,input().split()) map(int,input().split()) N ans = max(ans, sum(cur[idx:])) max(ans, sum(cur[idx:])) ans V = list(map(int,input().split())) list(map(int,input().split())) V cur = V[:a] + V[N-b:] V[:a] + V[N-b:] cur
N, K = map(int,input().split())
V = list(map(int,input().split()))

ans = 0

for a in range(min(N,K)+1):
    for b in range(min(N,K)-a+1):
        cur = V[:a] + V[N-b:]
        cur.sort()

        idx = 0
        while idx < min(K-a-b, len(cur)):
            if cur[idx] > 0: break
            else: idx += 1
        
        ans = max(ans, sum(cur[idx:]))
    
print(ans)