from heapq import heappush, heappop
from random import randint
from time import time

class PriorityQueue(object):
    def __init__(self):
        self.queue = []
    def push(self, value):
        heappush(self.queue, value)
    def pop(self):
        return heappop(self.queue)
    def __len__(self):
        return len(self.queue)
    def __contains__(self, item):
        return item in self.queue

n,m = map(int,input().split())
v = list(map(int,input().split()))

ans = 0

#取得する操作を何回行うか？
for i in range(0,m+1):

	#操作残り回数
	lef = m-i

	hp = PriorityQueue()
	#左側からどれだけ取るか？
	for j in range(0,i+1):
		if j>n :
			break

		#左側からj個取る
		for k in range(0,j):
			hp.push(v[k])

		#右側から i-j個取る
		for k in range(0,i-j):
			if n-1-k < j:
				break
			hp.push(v[n-1-k])

		#minusは戻す
		for k in range(0,lef):
			if len(hp) == 0:
				break
			top = hp.pop()
			if top>=0 :
				hp.push(top)
				break

		ss = 0
		while len(hp)>0:
			ss += hp.pop()

		ans = max(ans,ss)

print(ans) from heapq import heappush, heappop from random import randint from time import time class PriorityQueue(object):
    def __init__(self):
        self.queue = []
    def push(self, value):
        heappush(self.queue, value)
    def pop(self):
        return heappop(self.queue)
    def __len__(self):
        return len(self.queue)
    def __contains__(self, item):
        return item in self.queue PriorityQueue def __init__(self):
        self.queue = []
     __init__ self.queue = [] self.queue self queue [] self self def push(self, value):
        heappush(self.queue, value)
     push heappush(self.queue, value) heappush self.queue self queue value self self value value def pop(self):
        return heappop(self.queue)
     pop return heappop(self.queue) heappop(self.queue) heappop self.queue self queue self self def __len__(self):
        return len(self.queue)
     __len__ return len(self.queue) len(self.queue) len self.queue self queue self self def __contains__(self, item):
        return item in self.queue __contains__ return item in self.queue item in self.queue item self.queue self queue self self item item object n,m = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split m 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(0,m+1):

	#操作残り回数
	lef = m-i

	hp = PriorityQueue()
	#左側からどれだけ取るか？
	for j in range(0,i+1):
		if j>n :
			break

		#左側からj個取る
		for k in range(0,j):
			hp.push(v[k])

		#右側から i-j個取る
		for k in range(0,i-j):
			if n-1-k < j:
				break
			hp.push(v[n-1-k])

		#minusは戻す
		for k in range(0,lef):
			if len(hp) == 0:
				break
			top = hp.pop()
			if top>=0 :
				hp.push(top)
				break

		ss = 0
		while len(hp)>0:
			ss += hp.pop()

		ans = max(ans,ss) i range(0,m+1) range 0 m+1 m 1 lef = m-i lef m-i m i hp = PriorityQueue() hp PriorityQueue() PriorityQueue for j in range(0,i+1):
		if j>n :
			break

		#左側からj個取る
		for k in range(0,j):
			hp.push(v[k])

		#右側から i-j個取る
		for k in range(0,i-j):
			if n-1-k < j:
				break
			hp.push(v[n-1-k])

		#minusは戻す
		for k in range(0,lef):
			if len(hp) == 0:
				break
			top = hp.pop()
			if top>=0 :
				hp.push(top)
				break

		ss = 0
		while len(hp)>0:
			ss += hp.pop()

		ans = max(ans,ss) j range(0,i+1) range 0 i+1 i 1 if j>n :
			break

		#左側からj個取る
		 j>n j n break for k in range(0,j):
			hp.push(v[k])

		#右側から i-j個取る
		 k range(0,j) range 0 j hp.push(v[k]) hp.push hp push v[k] v k for k in range(0,i-j):
			if n-1-k < j:
				break
			hp.push(v[n-1-k])

		#minusは戻す
		 k range(0,i-j) range 0 i-j i j if n-1-k < j:
				break
			 n-1-k < j n-1-k n-1 n 1 k j break hp.push(v[n-1-k]) hp.push hp push v[n-1-k] v n-1-k n-1 n 1 k for k in range(0,lef):
			if len(hp) == 0:
				break
			top = hp.pop()
			if top>=0 :
				hp.push(top)
				break

		 k range(0,lef) range 0 lef if len(hp) == 0:
				break
			 len(hp) == 0 len(hp) len hp 0 break top = hp.pop() top hp.pop() hp.pop hp pop if top>=0 :
				hp.push(top)
				break

		 top>=0 top 0 hp.push(top) hp.push hp push top break ss = 0 ss 0 while len(hp)>0:
			ss += hp.pop()

		 len(hp)>0 len(hp) len hp 0 ss += hp.pop() ss hp.pop() hp.pop hp pop ans = max(ans,ss) ans max(ans,ss) max ans ss print(ans) print ans v = list(map(int,input().split())) list(map(int,input().split())) v n,m = map(int,input().split()) map(int,input().split()) n m = map(int,input().split()) map(int,input().split()) m lef = m-i m-i lef ans = 0 0 ans class PriorityQueue(object):
    def __init__(self):
        self.queue = []
    def push(self, value):
        heappush(self.queue, value)
    def pop(self):
        return heappop(self.queue)
    def __len__(self):
        return len(self.queue)
    def __contains__(self, item):
        return item in self.queue class PriorityQueue(object):
    def __init__(self):
        self.queue = []
    def push(self, value):
        heappush(self.queue, value)
    def pop(self):
        return heappop(self.queue)
    def __len__(self):
        return len(self.queue)
    def __contains__(self, item):
        return item in self.queue PriorityQueue ss = 0 0 ss hp = PriorityQueue() PriorityQueue() hp ss += hp.pop() hp.pop() ss top = hp.pop() hp.pop() top ans = max(ans,ss) max(ans,ss) ans
from heapq import heappush, heappop
from random import randint
from time import time

class PriorityQueue(object):
    def __init__(self):
        self.queue = []
    def push(self, value):
        heappush(self.queue, value)
    def pop(self):
        return heappop(self.queue)
    def __len__(self):
        return len(self.queue)
    def __contains__(self, item):
        return item in self.queue

n,m = map(int,input().split())
v = list(map(int,input().split()))

ans = 0

#取得する操作を何回行うか？
for i in range(0,m+1):

	#操作残り回数
	lef = m-i

	hp = PriorityQueue()
	#左側からどれだけ取るか？
	for j in range(0,i+1):
		if j>n :
			break

		#左側からj個取る
		for k in range(0,j):
			hp.push(v[k])

		#右側から i-j個取る
		for k in range(0,i-j):
			if n-1-k < j:
				break
			hp.push(v[n-1-k])

		#minusは戻す
		for k in range(0,lef):
			if len(hp) == 0:
				break
			top = hp.pop()
			if top>=0 :
				hp.push(top)
				break

		ss = 0
		while len(hp)>0:
			ss += hp.pop()

		ans = max(ans,ss)

print(ans)