import heapq
from collections import deque
n , k = map(int,input().split())
v = list(map(int,input().split()))
ans = 0
for i in range(n+1):
    for j in range(n+1):
        if i+j > n or i+j > k:
            continue
        p = v[:]
        d = deque(p)
        a = []
        heapq.heapify(a)
        for t in range(i):
            heapq.heappush(a,d.popleft())
        for l in range(j):
            heapq.heappush(a,d.pop())
        nokori = k-i-j
        for s in range(nokori):
            if a:
                now = heapq.heappop(a)
                if now > 0:
                    heapq.heappush(a,now)
                    break
            else:
                break
        ans = max(ans,sum(a))
print(ans) import heapq heapq from collections import deque 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 i in range(n+1):
    for j in range(n+1):
        if i+j > n or i+j > k:
            continue
        p = v[:]
        d = deque(p)
        a = []
        heapq.heapify(a)
        for t in range(i):
            heapq.heappush(a,d.popleft())
        for l in range(j):
            heapq.heappush(a,d.pop())
        nokori = k-i-j
        for s in range(nokori):
            if a:
                now = heapq.heappop(a)
                if now > 0:
                    heapq.heappush(a,now)
                    break
            else:
                break
        ans = max(ans,sum(a)) i range(n+1) range n+1 n 1 for j in range(n+1):
        if i+j > n or i+j > k:
            continue
        p = v[:]
        d = deque(p)
        a = []
        heapq.heapify(a)
        for t in range(i):
            heapq.heappush(a,d.popleft())
        for l in range(j):
            heapq.heappush(a,d.pop())
        nokori = k-i-j
        for s in range(nokori):
            if a:
                now = heapq.heappop(a)
                if now > 0:
                    heapq.heappush(a,now)
                    break
            else:
                break
        ans = max(ans,sum(a)) j range(n+1) range n+1 n 1 if i+j > n or i+j > k:
            continue
         i+j > n or i+j > k i+j > n i+j i j n i+j > k i+j i j k continue p = v[:] p v[:] v : d = deque(p) d deque(p) deque p a = [] a [] heapq.heapify(a) heapq.heapify heapq heapify a for t in range(i):
            heapq.heappush(a,d.popleft())
         t range(i) range i heapq.heappush(a,d.popleft()) heapq.heappush heapq heappush a d.popleft() d.popleft d popleft for l in range(j):
            heapq.heappush(a,d.pop())
         l range(j) range j heapq.heappush(a,d.pop()) heapq.heappush heapq heappush a d.pop() d.pop d pop nokori = k-i-j nokori k-i-j k-i k i j for s in range(nokori):
            if a:
                now = heapq.heappop(a)
                if now > 0:
                    heapq.heappush(a,now)
                    break
            else:
                break
         s range(nokori) range nokori if a:
                now = heapq.heappop(a)
                if now > 0:
                    heapq.heappush(a,now)
                    break
            else:
                break
         a now = heapq.heappop(a) now heapq.heappop(a) heapq.heappop heapq heappop a if now > 0:
                    heapq.heappush(a,now)
                    break
             now > 0 now 0 heapq.heappush(a,now) heapq.heappush heapq heappush a now break break ans = max(ans,sum(a)) ans max(ans,sum(a)) max ans sum(a) sum a print(ans) print ans nokori = k-i-j k-i-j nokori v = list(map(int,input().split())) list(map(int,input().split())) v n , k = map(int,input().split()) map(int,input().split()) n now = heapq.heappop(a) heapq.heappop(a) now a = [] [] a ans = max(ans,sum(a)) max(ans,sum(a)) ans k = map(int,input().split()) map(int,input().split()) k p = v[:] v[:] p ans = 0 0 ans d = deque(p) deque(p) d
import heapq
from collections import deque
n , k = map(int,input().split())
v = list(map(int,input().split()))
ans = 0
for i in range(n+1):
    for j in range(n+1):
        if i+j > n or i+j > k:
            continue
        p = v[:]
        d = deque(p)
        a = []
        heapq.heapify(a)
        for t in range(i):
            heapq.heappush(a,d.popleft())
        for l in range(j):
            heapq.heappush(a,d.pop())
        nokori = k-i-j
        for s in range(nokori):
            if a:
                now = heapq.heappop(a)
                if now > 0:
                    heapq.heappush(a,now)
                    break
            else:
                break
        ans = max(ans,sum(a))
print(ans)