N, K = map(int, input().split())
V = list(map(int, input().split()))
lst = []
take = min(N, K)
ans = 0

for i in range(take+1):
    for j in range(take - i +1):
        lst = V[:i] + V[N - j:]
        lst.sort()
        cnt = 0
        for t in lst:
            if t < 0:
                cnt += 1
        d = min(cnt, K - ( i + j))
        del lst[:d]
        ans = max(ans, sum(lst))

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 lst = [] lst [] take = min(N, K) take min(N, K) min N K ans = 0 ans 0 for i in range(take+1):
    for j in range(take - i +1):
        lst = V[:i] + V[N - j:]
        lst.sort()
        cnt = 0
        for t in lst:
            if t < 0:
                cnt += 1
        d = min(cnt, K - ( i + j))
        del lst[:d]
        ans = max(ans, sum(lst)) i range(take+1) range take+1 take 1 for j in range(take - i +1):
        lst = V[:i] + V[N - j:]
        lst.sort()
        cnt = 0
        for t in lst:
            if t < 0:
                cnt += 1
        d = min(cnt, K - ( i + j))
        del lst[:d]
        ans = max(ans, sum(lst)) j range(take - i +1) range take - i +1 take - i take i 1 lst = V[:i] + V[N - j:] lst V[:i] + V[N - j:] V[:i] V :i i V[N - j:] V N - j: N - j N j lst.sort() lst.sort lst sort cnt = 0 cnt 0 for t in lst:
            if t < 0:
                cnt += 1
         t lst if t < 0:
                cnt += 1
         t < 0 t 0 cnt += 1 cnt 1 d = min(cnt, K - ( i + j)) d min(cnt, K - ( i + j)) min cnt K - ( i + j) K i + j i j del lst[:d] lst[:d] lst :d d ans = max(ans, sum(lst)) ans max(ans, sum(lst)) max ans sum(lst) sum lst print(ans) print ans lst = [] [] lst K = map(int, input().split()) map(int, input().split()) K ans = max(ans, sum(lst)) max(ans, sum(lst)) ans N, K = map(int, input().split()) map(int, input().split()) N cnt += 1 1 cnt cnt = 0 0 cnt d = min(cnt, K - ( i + j)) min(cnt, K - ( i + j)) d ans = 0 0 ans V = list(map(int, input().split())) list(map(int, input().split())) V lst = V[:i] + V[N - j:] V[:i] + V[N - j:] lst take = min(N, K) min(N, K) take
N, K = map(int, input().split())
V = list(map(int, input().split()))
lst = []
take = min(N, K)
ans = 0

for i in range(take+1):
    for j in range(take - i +1):
        lst = V[:i] + V[N - j:]
        lst.sort()
        cnt = 0
        for t in lst:
            if t < 0:
                cnt += 1
        d = min(cnt, K - ( i + j))
        del lst[:d]
        ans = max(ans, sum(lst))

print(ans)