import copy

N, K = map(int, input().split())
V = [int(i) for i in input().split()]

value = 0
# k+1個取って，ret-1個戻す
num = min(N,K)
for k in reversed(range(num)):
    for ret in range(K-k): 
        if (ret < k+1):
            for i in range(k+1+1): # 左右の分け方
                tmp = []
                V_tmp = copy.copy(V)
                tmp.extend(V_tmp[:i]) # 左端
                V_tmp = V_tmp[i:]
                if (k+1-i) > 0:
                    tmp.extend(V_tmp[-(k+1-i):]) #右端
                if V_tmp == []:
                    break
                tmp = list(filter(lambda x: x not in sorted(tmp)[:ret],tmp))
                value = max(value,sum(tmp))
print(value)