import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
#from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N, K = MAP()
V = LIST()

ans = 0
tmp_sum = 0

for i in range(1, min(K, N)+1):
	left = K-i
	for j in range(i+1):
		tmp = V[:j] + V[N-(i-j):]
		tmp.sort()
		idx = bisect_left(tmp, 0)
		ans = max(ans, sum(tmp) - sum(tmp[:min(idx, left)]))

print(ans) import sys, re sys re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase, ascii_uppercase, digits from bisect import bisect, bisect_left, insort, insort_left from heapq import heappush, heappop from functools import reduce, lru_cache def input(): return sys.stdin.readline().strip() input def INT(): return int(input()) INT def MAP(): return map(int, input().split()) MAP def LIST(): return list(map(int, input().split())) LIST def TUPLE(): return tuple(map(int, input().split())) TUPLE MAP() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) MAP() MAP def ZIP(n): return zip(*(MAP() for _ in range(n))) ZIP n n sys.setrecursionlimit(10 ** 9) sys.setrecursionlimit sys setrecursionlimit 10 ** 9 10 9 INF = float('inf') INF float('inf') float 'inf' mod = 10 ** 9 + 7 mod 10 ** 9 + 7 10 ** 9 10 9 7 N, K = MAP() N MAP() MAP K V = LIST() V LIST() LIST ans = 0 ans 0 tmp_sum = 0 tmp_sum 0 for i in range(1, min(K, N)+1):
	left = K-i
	for j in range(i+1):
		tmp = V[:j] + V[N-(i-j):]
		tmp.sort()
		idx = bisect_left(tmp, 0)
		ans = max(ans, sum(tmp) - sum(tmp[:min(idx, left)])) i range(1, min(K, N)+1) range 1 min(K, N)+1 min(K, N) min K N 1 left = K-i left K-i K i for j in range(i+1):
		tmp = V[:j] + V[N-(i-j):]
		tmp.sort()
		idx = bisect_left(tmp, 0)
		ans = max(ans, sum(tmp) - sum(tmp[:min(idx, left)])) j range(i+1) range i+1 i 1 tmp = V[:j] + V[N-(i-j):] tmp V[:j] + V[N-(i-j):] V[:j] V :j j V[N-(i-j):] V N-(i-j): N-(i-j) N i-j i j tmp.sort() tmp.sort tmp sort idx = bisect_left(tmp, 0) idx bisect_left(tmp, 0) bisect_left tmp 0 ans = max(ans, sum(tmp) - sum(tmp[:min(idx, left)])) ans max(ans, sum(tmp) - sum(tmp[:min(idx, left)])) max ans sum(tmp) - sum(tmp[:min(idx, left)]) sum(tmp) sum tmp sum(tmp[:min(idx, left)]) sum tmp[:min(idx, left)] tmp :min(idx, left) min(idx, left) min idx left print(ans) print ans ans = 0 0 ans def LIST(): return list(map(int, input().split())) def LIST(): return list(map(int, input().split())) LIST tmp = V[:j] + V[N-(i-j):] V[:j] + V[N-(i-j):] tmp def ZIP(n): return zip(*(MAP() for _ in range(n))) def ZIP(n): return zip(*(MAP() for _ in range(n))) ZIP N, K = MAP() MAP() N idx = bisect_left(tmp, 0) bisect_left(tmp, 0) idx tmp_sum = 0 0 tmp_sum INF = float('inf') float('inf') INF def INT(): return int(input()) def INT(): return int(input()) INT def TUPLE(): return tuple(map(int, input().split())) def TUPLE(): return tuple(map(int, input().split())) TUPLE K = MAP() MAP() K ans = max(ans, sum(tmp) - sum(tmp[:min(idx, left)])) max(ans, sum(tmp) - sum(tmp[:min(idx, left)])) ans mod = 10 ** 9 + 7 10 ** 9 + 7 mod left = K-i K-i left V = LIST() LIST() V def MAP(): return map(int, input().split()) def MAP(): return map(int, input().split()) MAP def input(): return sys.stdin.readline().strip() def input(): return sys.stdin.readline().strip() input
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
#from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N, K = MAP()
V = LIST()

ans = 0
tmp_sum = 0

for i in range(1, min(K, N)+1):
	left = K-i
	for j in range(i+1):
		tmp = V[:j] + V[N-(i-j):]
		tmp.sort()
		idx = bisect_left(tmp, 0)
		ans = max(ans, sum(tmp) - sum(tmp[:min(idx, left)]))

print(ans)
