import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
LIN=lambda : list(IN())
mod=1000000007

#+++++

def main():
	#a = int(input())
	n, k = IN()
	dq = LIN()
	rdq = dq[::-1]
	#s = input()
	max_v=0
	for left_get in range(k+1):
		for right_get in range(max(k-left_get+1,1)):
			if left_get+right_get>n:
				continue
			elif left_get==0 and right_get==0:
				continue
			nokori=k-left_get-right_get
			l=dq[:left_get]
			r=rdq[:right_get]
			#print(l, r)
			dd=(l+r)
			dd.sort(reverse=True)
			for _ in range(nokori):
				if dd[-1]>= 0:
					break
				dd.pop()
				if len(dd)==0:
					break
			r=sum(dd)
			max_v=max(max_v, r)
	print(max_v)
		
		
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret) import sys sys input_methods=['clipboard','file','key'] input_methods ['clipboard','file','key'] 'clipboard' 'file' 'key' using_method=0 using_method 0 input_method=input_methods[using_method] input_method input_methods[using_method] input_methods using_method IN=lambda : map(int, input().split()) IN lambda : map(int, input().split()) map(int, input().split()) map int input().split() ().split () input split LIN=lambda : list(IN()) LIN lambda : list(IN()) list(IN()) list IN() IN mod=1000000007 mod 1000000007 def main():
	#a = int(input())
	n, k = IN()
	dq = LIN()
	rdq = dq[::-1]
	#s = input()
	max_v=0
	for left_get in range(k+1):
		for right_get in range(max(k-left_get+1,1)):
			if left_get+right_get>n:
				continue
			elif left_get==0 and right_get==0:
				continue
			nokori=k-left_get-right_get
			l=dq[:left_get]
			r=rdq[:right_get]
			#print(l, r)
			dd=(l+r)
			dd.sort(reverse=True)
			for _ in range(nokori):
				if dd[-1]>= 0:
					break
				dd.pop()
				if len(dd)==0:
					break
			r=sum(dd)
			max_v=max(max_v, r)
	print(max_v)
		
		
	
	
#+++++ main n, k = IN() n IN() IN k dq = LIN() dq LIN() LIN rdq = dq[::-1] rdq dq[::-1] dq ::-1 -1 max_v=0 max_v 0 for left_get in range(k+1):
		for right_get in range(max(k-left_get+1,1)):
			if left_get+right_get>n:
				continue
			elif left_get==0 and right_get==0:
				continue
			nokori=k-left_get-right_get
			l=dq[:left_get]
			r=rdq[:right_get]
			#print(l, r)
			dd=(l+r)
			dd.sort(reverse=True)
			for _ in range(nokori):
				if dd[-1]>= 0:
					break
				dd.pop()
				if len(dd)==0:
					break
			r=sum(dd)
			max_v=max(max_v, r)
	 left_get range(k+1) range k+1 k 1 for right_get in range(max(k-left_get+1,1)):
			if left_get+right_get>n:
				continue
			elif left_get==0 and right_get==0:
				continue
			nokori=k-left_get-right_get
			l=dq[:left_get]
			r=rdq[:right_get]
			#print(l, r)
			dd=(l+r)
			dd.sort(reverse=True)
			for _ in range(nokori):
				if dd[-1]>= 0:
					break
				dd.pop()
				if len(dd)==0:
					break
			r=sum(dd)
			max_v=max(max_v, r)
	 right_get range(max(k-left_get+1,1)) range max(k-left_get+1,1) max k-left_get+1 k-left_get k left_get 1 1 if left_get+right_get>n:
				continue
			elif left_get==0 and right_get==0:
				continue
			 left_get+right_get>n left_get+right_get left_get right_get n continue elif left_get==0 and right_get==0:
				continue
			 left_get==0 and right_get==0 left_get==0 left_get 0 right_get==0 right_get 0 continue nokori=k-left_get-right_get nokori k-left_get-right_get k-left_get k left_get right_get l=dq[:left_get] l dq[:left_get] dq :left_get left_get r=rdq[:right_get] r rdq[:right_get] rdq :right_get right_get dd=(l+r) dd l+r l r dd.sort(reverse=True) dd.sort dd sort reverse=True reverse True for _ in range(nokori):
				if dd[-1]>= 0:
					break
				dd.pop()
				if len(dd)==0:
					break
			 _ range(nokori) range nokori if dd[-1]>= 0:
					break
				 dd[-1]>= 0 dd[-1] dd -1 0 break dd.pop() dd.pop dd pop if len(dd)==0:
					break
			 len(dd)==0 len(dd) len dd 0 break r=sum(dd) r sum(dd) sum dd max_v=max(max_v, r) max_v max(max_v, r) max max_v r print(max_v) print max_v isTest=False isTest False def pa(v):
	if isTest:
		print(v)
		 pa if isTest:
		print(v)
		 isTest print(v) print v v v def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l input_clipboard import clipboard clipboard input_text=clipboard.get() input_text clipboard.get() clipboard.get clipboard get input_l=input_text.splitlines() input_l input_text.splitlines() input_text.splitlines input_text splitlines for l in input_l:
		yield l l input_l yield l l if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret) __name__ == "__main__" __name__ "__main__" if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	 sys.platform =='ios' sys.platform sys platform 'ios' if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		 input_method==input_methods[0] input_method input_methods[0] input_methods 0 ic=input_clipboard() ic input_clipboard() input_clipboard input = lambda : ic.__next__() input lambda : ic.__next__() ic.__next__() ic.__next__ ic __next__ elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		 input_method==input_methods[1] input_method input_methods[1] input_methods 1 sys.stdin=open('inputFile.txt') sys.stdin sys stdin open('inputFile.txt') open 'inputFile.txt' isTest=True isTest True ret = main() ret main() main if ret is not None:
		print(ret) ret is not None ret None print(ret) print ret isTest=True True isTest def pa(v):
	if isTest:
		print(v)
		 def pa(v):
	if isTest:
		print(v)
		 pa isTest=False False isTest ret = main() main() ret LIN=lambda : list(IN()) lambda : list(IN()) LIN mod=1000000007 1000000007 mod ic=input_clipboard() input_clipboard() ic input_methods=['clipboard','file','key'] ['clipboard','file','key'] input_methods IN=lambda : map(int, input().split()) lambda : map(int, input().split()) IN def main():
	#a = int(input())
	n, k = IN()
	dq = LIN()
	rdq = dq[::-1]
	#s = input()
	max_v=0
	for left_get in range(k+1):
		for right_get in range(max(k-left_get+1,1)):
			if left_get+right_get>n:
				continue
			elif left_get==0 and right_get==0:
				continue
			nokori=k-left_get-right_get
			l=dq[:left_get]
			r=rdq[:right_get]
			#print(l, r)
			dd=(l+r)
			dd.sort(reverse=True)
			for _ in range(nokori):
				if dd[-1]>= 0:
					break
				dd.pop()
				if len(dd)==0:
					break
			r=sum(dd)
			max_v=max(max_v, r)
	print(max_v)
		
		
	
	
#+++++ def main():
	#a = int(input())
	n, k = IN()
	dq = LIN()
	rdq = dq[::-1]
	#s = input()
	max_v=0
	for left_get in range(k+1):
		for right_get in range(max(k-left_get+1,1)):
			if left_get+right_get>n:
				continue
			elif left_get==0 and right_get==0:
				continue
			nokori=k-left_get-right_get
			l=dq[:left_get]
			r=rdq[:right_get]
			#print(l, r)
			dd=(l+r)
			dd.sort(reverse=True)
			for _ in range(nokori):
				if dd[-1]>= 0:
					break
				dd.pop()
				if len(dd)==0:
					break
			r=sum(dd)
			max_v=max(max_v, r)
	print(max_v)
		
		
	
	
#+++++ main using_method=0 0 using_method input_method=input_methods[using_method] input_methods[using_method] input_method def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l input_clipboard input = lambda : ic.__next__() lambda : ic.__next__() input
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
LIN=lambda : list(IN())
mod=1000000007

#+++++

def main():
	#a = int(input())
	n, k = IN()
	dq = LIN()
	rdq = dq[::-1]
	#s = input()
	max_v=0
	for left_get in range(k+1):
		for right_get in range(max(k-left_get+1,1)):
			if left_get+right_get>n:
				continue
			elif left_get==0 and right_get==0:
				continue
			nokori=k-left_get-right_get
			l=dq[:left_get]
			r=rdq[:right_get]
			#print(l, r)
			dd=(l+r)
			dd.sort(reverse=True)
			for _ in range(nokori):
				if dd[-1]>= 0:
					break
				dd.pop()
				if len(dd)==0:
					break
			r=sum(dd)
			max_v=max(max_v, r)
	print(max_v)
		
		
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)