n, k = map(int,input().split())
targ = min(n, k)
v = list(map(int,input().split()))
"""
i…左を取る回数
j…右を取る回数
残り回数 k-(i+j)
"""
ans = -10**18
for i in range(targ+1):
	for j in range(targ-i+1):
		#print(i, j)
		nl = v[:i] + v[n-j:]
		nl.sort()
		#print(nl)
		tmp = sum(nl)
		for t in range(min(k-(i+j), i+j)):
			tmp = max(tmp, tmp-nl[t])
			#print("行いましたよ!")
		#print(tmp)
		ans = max(tmp, ans)
print(ans) n, k = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split k targ = min(n, k) targ min(n, k) min n k v = list(map(int,input().split())) v list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split """
i…左を取る回数
j…右を取る回数
残り回数 k-(i+j)
""" ans = -10**18 ans -10**18 -10 18 for i in range(targ+1):
	for j in range(targ-i+1):
		#print(i, j)
		nl = v[:i] + v[n-j:]
		nl.sort()
		#print(nl)
		tmp = sum(nl)
		for t in range(min(k-(i+j), i+j)):
			tmp = max(tmp, tmp-nl[t])
			#print("行いましたよ!")
		#print(tmp)
		ans = max(tmp, ans) i range(targ+1) range targ+1 targ 1 for j in range(targ-i+1):
		#print(i, j)
		nl = v[:i] + v[n-j:]
		nl.sort()
		#print(nl)
		tmp = sum(nl)
		for t in range(min(k-(i+j), i+j)):
			tmp = max(tmp, tmp-nl[t])
			#print("行いましたよ!")
		#print(tmp)
		ans = max(tmp, ans) j range(targ-i+1) range targ-i+1 targ-i targ i 1 nl = v[:i] + v[n-j:] nl v[:i] + v[n-j:] v[:i] v :i i v[n-j:] v n-j: n-j n j nl.sort() nl.sort nl sort tmp = sum(nl) tmp sum(nl) sum nl for t in range(min(k-(i+j), i+j)):
			tmp = max(tmp, tmp-nl[t])
			#print("行いましたよ!")
		#print(tmp)
		 t range(min(k-(i+j), i+j)) range min(k-(i+j), i+j) min k-(i+j) k i+j i j i+j i j tmp = max(tmp, tmp-nl[t]) tmp max(tmp, tmp-nl[t]) max tmp tmp-nl[t] tmp nl[t] nl t ans = max(tmp, ans) ans max(tmp, ans) max tmp ans print(ans) print ans tmp = max(tmp, tmp-nl[t]) max(tmp, tmp-nl[t]) tmp k = map(int,input().split()) map(int,input().split()) k nl = v[:i] + v[n-j:] v[:i] + v[n-j:] nl n, k = map(int,input().split()) map(int,input().split()) n ans = max(tmp, ans) max(tmp, ans) ans tmp = sum(nl) sum(nl) tmp ans = -10**18 -10**18 ans targ = min(n, k) min(n, k) targ v = list(map(int,input().split())) list(map(int,input().split())) v
n, k = map(int,input().split())
targ = min(n, k)
v = list(map(int,input().split()))
"""
i…左を取る回数
j…右を取る回数
残り回数 k-(i+j)
"""
ans = -10**18
for i in range(targ+1):
	for j in range(targ-i+1):
		#print(i, j)
		nl = v[:i] + v[n-j:]
		nl.sort()
		#print(nl)
		tmp = sum(nl)
		for t in range(min(k-(i+j), i+j)):
			tmp = max(tmp, tmp-nl[t])
			#print("行いましたよ!")
		#print(tmp)
		ans = max(tmp, ans)
print(ans)