#template
def inputlist(): return [int(k) for k in input().split()]
#template
N,K = inputlist()
V = inputlist()
n = min(N,K)
ans = 0
from collections import deque
for a in range(n+1):
    for b in range(n+1):
        li = []
        if a+b > n:
            continue
        c = K-(a+b)
        que = deque(V)
        for i in range(a):
            k = que.popleft()
            li.append(k)
        for j in range(b):
            s = que.pop()
            li.append(s)
        li.sort()
        index = 0
        for i in range(len(li)):
            if li[i] < 0:
                index +=1
        na = min(index,c)
        suma = sum(li[na:])
        ans = max(ans,suma)

print(ans) int(k) for k in input().split() for k in input().split() k input().split() ().split () input split for k in input().split() int(k) int k def inputlist(): return [int(k) for k in input().split()]
#template inputlist N,K = inputlist() N inputlist() inputlist K V = inputlist() V inputlist() inputlist n = min(N,K) n min(N,K) min N K ans = 0 ans 0 from collections import deque for a in range(n+1):
    for b in range(n+1):
        li = []
        if a+b > n:
            continue
        c = K-(a+b)
        que = deque(V)
        for i in range(a):
            k = que.popleft()
            li.append(k)
        for j in range(b):
            s = que.pop()
            li.append(s)
        li.sort()
        index = 0
        for i in range(len(li)):
            if li[i] < 0:
                index +=1
        na = min(index,c)
        suma = sum(li[na:])
        ans = max(ans,suma) a range(n+1) range n+1 n 1 for b in range(n+1):
        li = []
        if a+b > n:
            continue
        c = K-(a+b)
        que = deque(V)
        for i in range(a):
            k = que.popleft()
            li.append(k)
        for j in range(b):
            s = que.pop()
            li.append(s)
        li.sort()
        index = 0
        for i in range(len(li)):
            if li[i] < 0:
                index +=1
        na = min(index,c)
        suma = sum(li[na:])
        ans = max(ans,suma) b range(n+1) range n+1 n 1 li = [] li [] if a+b > n:
            continue
         a+b > n a+b a b n continue c = K-(a+b) c K-(a+b) K a+b a b que = deque(V) que deque(V) deque V for i in range(a):
            k = que.popleft()
            li.append(k)
         i range(a) range a k = que.popleft() k que.popleft() que.popleft que popleft li.append(k) li.append li append k for j in range(b):
            s = que.pop()
            li.append(s)
         j range(b) range b s = que.pop() s que.pop() que.pop que pop li.append(s) li.append li append s li.sort() li.sort li sort index = 0 index 0 for i in range(len(li)):
            if li[i] < 0:
                index +=1
         i range(len(li)) range len(li) len li if li[i] < 0:
                index +=1
         li[i] < 0 li[i] li i 0 index +=1 index 1 na = min(index,c) na min(index,c) min index c suma = sum(li[na:]) suma sum(li[na:]) sum li[na:] li na: na ans = max(ans,suma) ans max(ans,suma) max ans suma print(ans) print ans li = [] [] li c = K-(a+b) K-(a+b) c n = min(N,K) min(N,K) n index +=1 1 index V = inputlist() inputlist() V def inputlist(): return [int(k) for k in input().split()]
#template def inputlist(): return [int(k) for k in input().split()]
#template inputlist suma = sum(li[na:]) sum(li[na:]) suma k = que.popleft() que.popleft() k K = inputlist() inputlist() K na = min(index,c) min(index,c) na N,K = inputlist() inputlist() N ans = max(ans,suma) max(ans,suma) ans que = deque(V) deque(V) que index = 0 0 index ans = 0 0 ans s = que.pop() que.pop() s
#template
def inputlist(): return [int(k) for k in input().split()]
#template
N,K = inputlist()
V = inputlist()
n = min(N,K)
ans = 0
from collections import deque
for a in range(n+1):
    for b in range(n+1):
        li = []
        if a+b > n:
            continue
        c = K-(a+b)
        que = deque(V)
        for i in range(a):
            k = que.popleft()
            li.append(k)
        for j in range(b):
            s = que.pop()
            li.append(s)
        li.sort()
        index = 0
        for i in range(len(li)):
            if li[i] < 0:
                index +=1
        na = min(index,c)
        suma = sum(li[na:])
        ans = max(ans,suma)

print(ans)