import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()


def main():
	n,k=MI()
	V=LI()

	ans=0

	for a in range(min(n+1,k+1)):
		for b in range(min(n-a+1,k-a+1)):
			S=[]
			S+=V[:a]
			S+=V[n-b:]
			S.sort()
			tmp=sum(S)
			cnt=max(0,k-a-b)
			for i in range(min(a+b,cnt)):

				if S[i]<0:
					tmp-=S[i]
				else:
					break
			ans=max(ans,tmp)
	print(ans)










if __name__ == "__main__":
	main() import sys sys input = sys.stdin.buffer.readline input sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline def RD(): return input().rstrip().decode() RD def II(): return int(input()) II def FI(): return int(input()) FI def MI(): return map(int,input().split()) MI def MF(): return map(float,input().split()) MF def LI(): return list(map(int,input().split())) LI def LF(): return list(map(float,input().split())) LF def TI(): return tuple(map(int,input().split()))
# rstrip().decode() TI def main():
	n,k=MI()
	V=LI()

	ans=0

	for a in range(min(n+1,k+1)):
		for b in range(min(n-a+1,k-a+1)):
			S=[]
			S+=V[:a]
			S+=V[n-b:]
			S.sort()
			tmp=sum(S)
			cnt=max(0,k-a-b)
			for i in range(min(a+b,cnt)):

				if S[i]<0:
					tmp-=S[i]
				else:
					break
			ans=max(ans,tmp)
	print(ans) main n,k=MI() n MI() MI k V=LI() V LI() LI ans=0 ans 0 for a in range(min(n+1,k+1)):
		for b in range(min(n-a+1,k-a+1)):
			S=[]
			S+=V[:a]
			S+=V[n-b:]
			S.sort()
			tmp=sum(S)
			cnt=max(0,k-a-b)
			for i in range(min(a+b,cnt)):

				if S[i]<0:
					tmp-=S[i]
				else:
					break
			ans=max(ans,tmp)
	 a range(min(n+1,k+1)) range min(n+1,k+1) min n+1 n 1 k+1 k 1 for b in range(min(n-a+1,k-a+1)):
			S=[]
			S+=V[:a]
			S+=V[n-b:]
			S.sort()
			tmp=sum(S)
			cnt=max(0,k-a-b)
			for i in range(min(a+b,cnt)):

				if S[i]<0:
					tmp-=S[i]
				else:
					break
			ans=max(ans,tmp)
	 b range(min(n-a+1,k-a+1)) range min(n-a+1,k-a+1) min n-a+1 n-a n a 1 k-a+1 k-a k a 1 S=[] S [] S+=V[:a] S V[:a] V :a a S+=V[n-b:] S V[n-b:] V n-b: n-b n b S.sort() S.sort S sort tmp=sum(S) tmp sum(S) sum S cnt=max(0,k-a-b) cnt max(0,k-a-b) max 0 k-a-b k-a k a b for i in range(min(a+b,cnt)):

				if S[i]<0:
					tmp-=S[i]
				else:
					break
			 i range(min(a+b,cnt)) range min(a+b,cnt) min a+b a b cnt if S[i]<0:
					tmp-=S[i]
				else:
					break
			 S[i]<0 S[i] S i 0 tmp-=S[i] tmp S[i] S i break ans=max(ans,tmp) ans max(ans,tmp) max ans tmp print(ans) print ans if __name__ == "__main__":
	main() __name__ == "__main__" __name__ "__main__" main() main input = sys.stdin.buffer.readline sys.stdin.buffer.readline input def II(): return int(input()) def II(): return int(input()) II def TI(): return tuple(map(int,input().split()))
# rstrip().decode() def TI(): return tuple(map(int,input().split()))
# rstrip().decode() TI def MI(): return map(int,input().split()) def MI(): return map(int,input().split()) MI def LF(): return list(map(float,input().split())) def LF(): return list(map(float,input().split())) LF def LI(): return list(map(int,input().split())) def LI(): return list(map(int,input().split())) LI def main():
	n,k=MI()
	V=LI()

	ans=0

	for a in range(min(n+1,k+1)):
		for b in range(min(n-a+1,k-a+1)):
			S=[]
			S+=V[:a]
			S+=V[n-b:]
			S.sort()
			tmp=sum(S)
			cnt=max(0,k-a-b)
			for i in range(min(a+b,cnt)):

				if S[i]<0:
					tmp-=S[i]
				else:
					break
			ans=max(ans,tmp)
	print(ans) def main():
	n,k=MI()
	V=LI()

	ans=0

	for a in range(min(n+1,k+1)):
		for b in range(min(n-a+1,k-a+1)):
			S=[]
			S+=V[:a]
			S+=V[n-b:]
			S.sort()
			tmp=sum(S)
			cnt=max(0,k-a-b)
			for i in range(min(a+b,cnt)):

				if S[i]<0:
					tmp-=S[i]
				else:
					break
			ans=max(ans,tmp)
	print(ans) main def FI(): return int(input()) def FI(): return int(input()) FI def RD(): return input().rstrip().decode() def RD(): return input().rstrip().decode() RD def MF(): return map(float,input().split()) def MF(): return map(float,input().split()) MF
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()


def main():
	n,k=MI()
	V=LI()

	ans=0

	for a in range(min(n+1,k+1)):
		for b in range(min(n-a+1,k-a+1)):
			S=[]
			S+=V[:a]
			S+=V[n-b:]
			S.sort()
			tmp=sum(S)
			cnt=max(0,k-a-b)
			for i in range(min(a+b,cnt)):

				if S[i]<0:
					tmp-=S[i]
				else:
					break
			ans=max(ans,tmp)
	print(ans)










if __name__ == "__main__":
	main()
