N, K = map(int, input().split())
V = list(map(int, input().split()))

ans = 0
for left in range(N + 1):
    for right in range(N + 1):
        if left + right > N or left + right > K:
            continue
        L = V[:left]
        R = V[::-1][:right]

        A = L + R
        A.sort(reverse=True)
        k = K - (left + right)
        while k > 0 and A and A[-1] < 0:
            A.pop()
            k -= 1
        ans = max(ans, sum(A))
print(ans) N, K = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split 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 ans = 0 ans 0 for left in range(N + 1):
    for right in range(N + 1):
        if left + right > N or left + right > K:
            continue
        L = V[:left]
        R = V[::-1][:right]

        A = L + R
        A.sort(reverse=True)
        k = K - (left + right)
        while k > 0 and A and A[-1] < 0:
            A.pop()
            k -= 1
        ans = max(ans, sum(A)) left range(N + 1) range N + 1 N 1 for right in range(N + 1):
        if left + right > N or left + right > K:
            continue
        L = V[:left]
        R = V[::-1][:right]

        A = L + R
        A.sort(reverse=True)
        k = K - (left + right)
        while k > 0 and A and A[-1] < 0:
            A.pop()
            k -= 1
        ans = max(ans, sum(A)) right range(N + 1) range N + 1 N 1 if left + right > N or left + right > K:
            continue
         left + right > N or left + right > K left + right > N left + right left right N left + right > K left + right left right K continue L = V[:left] L V[:left] V :left left R = V[::-1][:right] R V[::-1][:right] [::-1] V ::-1 -1 :right right A = L + R A L + R L R A.sort(reverse=True) A.sort A sort reverse=True reverse True k = K - (left + right) k K - (left + right) K left + right left right while k > 0 and A and A[-1] < 0:
            A.pop()
            k -= 1
         k > 0 and A and A[-1] < 0 k > 0 and A k > 0 k 0 A A[-1] < 0 A[-1] A -1 0 A.pop() A.pop A pop k -= 1 k 1 ans = max(ans, sum(A)) ans max(ans, sum(A)) max ans sum(A) sum A print(ans) print ans k = K - (left + right) K - (left + right) k R = V[::-1][:right] V[::-1][:right] R k -= 1 1 k L = V[:left] V[:left] L V = list(map(int, input().split())) list(map(int, input().split())) V K = map(int, input().split()) map(int, input().split()) K ans = 0 0 ans ans = max(ans, sum(A)) max(ans, sum(A)) ans N, K = map(int, input().split()) map(int, input().split()) N A = L + R L + R A
N, K = map(int, input().split())
V = list(map(int, input().split()))

ans = 0
for left in range(N + 1):
    for right in range(N + 1):
        if left + right > N or left + right > K:
            continue
        L = V[:left]
        R = V[::-1][:right]

        A = L + R
        A.sort(reverse=True)
        k = K - (left + right)
        while k > 0 and A and A[-1] < 0:
            A.pop()
            k -= 1
        ans = max(ans, sum(A))
print(ans)
