# import itertools
# import pprint
import copy
from collections import deque

gem,ope = map(int,input().split())
vlist = deque(map(int,input().split()))

ans = 0

for l in range(ope+1):
  for r in range(ope-l+1):
    if l+r>ope or l+r>gem:
      break

    x   = ope-l-r
    now = []
    deq = copy.copy(vlist) 

    for i in range(l):
      now.append(deq.popleft())
    for j in range(r):
      now.append(deq.pop())
    for k in range(x):
      if now==[]:
        break
      if min(now)<0:
        now.remove(min(now))
    
    if ans<sum(now):
      ans = sum(now)

print(ans) import copy copy from collections import deque gem,ope = map(int,input().split()) gem map(int,input().split()) map int input().split() ().split () input split ope vlist = deque(map(int,input().split())) vlist deque(map(int,input().split())) deque map(int,input().split()) map int input().split() ().split () input split ans = 0 ans 0 for l in range(ope+1):
  for r in range(ope-l+1):
    if l+r>ope or l+r>gem:
      break

    x   = ope-l-r
    now = []
    deq = copy.copy(vlist) 

    for i in range(l):
      now.append(deq.popleft())
    for j in range(r):
      now.append(deq.pop())
    for k in range(x):
      if now==[]:
        break
      if min(now)<0:
        now.remove(min(now))
    
    if ans<sum(now):
      ans = sum(now) l range(ope+1) range ope+1 ope 1 for r in range(ope-l+1):
    if l+r>ope or l+r>gem:
      break

    x   = ope-l-r
    now = []
    deq = copy.copy(vlist) 

    for i in range(l):
      now.append(deq.popleft())
    for j in range(r):
      now.append(deq.pop())
    for k in range(x):
      if now==[]:
        break
      if min(now)<0:
        now.remove(min(now))
    
    if ans<sum(now):
      ans = sum(now) r range(ope-l+1) range ope-l+1 ope-l ope l 1 if l+r>ope or l+r>gem:
      break

     l+r>ope or l+r>gem l+r>ope l+r l r ope l+r>gem l+r l r gem break x   = ope-l-r x ope-l-r ope-l ope l r now = [] now [] deq = copy.copy(vlist) deq copy.copy(vlist) copy.copy copy copy vlist for i in range(l):
      now.append(deq.popleft())
     i range(l) range l now.append(deq.popleft()) now.append now append deq.popleft() deq.popleft deq popleft for j in range(r):
      now.append(deq.pop())
     j range(r) range r now.append(deq.pop()) now.append now append deq.pop() deq.pop deq pop for k in range(x):
      if now==[]:
        break
      if min(now)<0:
        now.remove(min(now))
    
     k range(x) range x if now==[]:
        break
       now==[] now [] break if min(now)<0:
        now.remove(min(now))
    
     min(now)<0 min(now) min now 0 now.remove(min(now)) now.remove now remove min(now) min now if ans<sum(now):
      ans = sum(now) ans<sum(now) ans sum(now) sum now ans = sum(now) ans sum(now) sum now print(ans) print ans ope = map(int,input().split()) map(int,input().split()) ope ans = 0 0 ans gem,ope = map(int,input().split()) map(int,input().split()) gem now = [] [] now ans = sum(now) sum(now) ans x   = ope-l-r ope-l-r x deq = copy.copy(vlist) copy.copy(vlist) deq vlist = deque(map(int,input().split())) deque(map(int,input().split())) vlist
# import itertools
# import pprint
import copy
from collections import deque

gem,ope = map(int,input().split())
vlist = deque(map(int,input().split()))

ans = 0

for l in range(ope+1):
  for r in range(ope-l+1):
    if l+r>ope or l+r>gem:
      break

    x   = ope-l-r
    now = []
    deq = copy.copy(vlist) 

    for i in range(l):
      now.append(deq.popleft())
    for j in range(r):
      now.append(deq.pop())
    for k in range(x):
      if now==[]:
        break
      if min(now)<0:
        now.remove(min(now))
    
    if ans<sum(now):
      ans = sum(now)

print(ans)
