import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

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

ans = 0

for l in range(min(N, K) + 1): #左側から取る個数
    left = N - l #筒に残っている数
    for r in range(min(left, K - l) + 1): #右側から取る個数
        k = K - l - r #捨てる個数
        tmp = V[:l] + V[N - r:]
        tmp.sort(reverse = False)
        t = sum(tmp)
        for i in range(min(k, l + r)): #最大捨てることができる個数
            if tmp[i] < 0:
                t -= tmp[i]
            else:
                break
        
        ans = max(ans, t)

print (ans) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline sys.setrecursionlimit(10 ** 9) sys.setrecursionlimit sys setrecursionlimit 10 ** 9 10 9 MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 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 l in range(min(N, K) + 1): #左側から取る個数
    left = N - l #筒に残っている数
    for r in range(min(left, K - l) + 1): #右側から取る個数
        k = K - l - r #捨てる個数
        tmp = V[:l] + V[N - r:]
        tmp.sort(reverse = False)
        t = sum(tmp)
        for i in range(min(k, l + r)): #最大捨てることができる個数
            if tmp[i] < 0:
                t -= tmp[i]
            else:
                break
        
        ans = max(ans, t) l range(min(N, K) + 1) range min(N, K) + 1 min(N, K) min N K 1 left = N - l left N - l N l for r in range(min(left, K - l) + 1): #右側から取る個数
        k = K - l - r #捨てる個数
        tmp = V[:l] + V[N - r:]
        tmp.sort(reverse = False)
        t = sum(tmp)
        for i in range(min(k, l + r)): #最大捨てることができる個数
            if tmp[i] < 0:
                t -= tmp[i]
            else:
                break
        
        ans = max(ans, t) r range(min(left, K - l) + 1) range min(left, K - l) + 1 min(left, K - l) min left K - l K l 1 k = K - l - r k K - l - r K - l K l r tmp = V[:l] + V[N - r:] tmp V[:l] + V[N - r:] V[:l] V :l l V[N - r:] V N - r: N - r N r tmp.sort(reverse = False) tmp.sort tmp sort reverse = False reverse False t = sum(tmp) t sum(tmp) sum tmp for i in range(min(k, l + r)): #最大捨てることができる個数
            if tmp[i] < 0:
                t -= tmp[i]
            else:
                break
        
         i range(min(k, l + r)) range min(k, l + r) min k l + r l r if tmp[i] < 0:
                t -= tmp[i]
            else:
                break
        
         tmp[i] < 0 tmp[i] tmp i 0 t -= tmp[i] t tmp[i] tmp i break ans = max(ans, t) ans max(ans, t) max ans t print (ans) print ans K = map(int, input().split()) map(int, input().split()) K ans = max(ans, t) max(ans, t) ans k = K - l - r K - l - r k t = sum(tmp) sum(tmp) t MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD tmp = V[:l] + V[N - r:] V[:l] + V[N - r:] tmp 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 left = N - l N - l left ans = 0 0 ans t -= tmp[i] tmp[i] t
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

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

ans = 0

for l in range(min(N, K) + 1): #左側から取る個数
    left = N - l #筒に残っている数
    for r in range(min(left, K - l) + 1): #右側から取る個数
        k = K - l - r #捨てる個数
        tmp = V[:l] + V[N - r:]
        tmp.sort(reverse = False)
        t = sum(tmp)
        for i in range(min(k, l + r)): #最大捨てることができる個数
            if tmp[i] < 0:
                t -= tmp[i]
            else:
                break
        
        ans = max(ans, t)

print (ans)