n, k = [int(a) for a in input().split()]
v = [int(a) for a in input().split()]


cap = min(n, k)
max_val = 0
for left in range(k):
    for right in range(cap - left):
        rest = k - (left + right)
        l_popped = v[:left]
        r_popped = v[-right:] if right > 0 else []
        popped = l_popped + r_popped

        popped.sort()

        first_positive = len(popped)
        for i, value in enumerate(popped):
            if value > 0:
                first_positive = i
                break

        sum_val = sum(popped[min(rest, first_positive):])
        if sum_val > max_val:
            max_val = sum_val

print(max_val)

