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

ans = 0
for l in range(N + 1):
    for r in range(N + 1):
        if l + r > N:
            continue
        k = K - (l + r)
        if k < 0:
            continue

        A = V[:l] + V[N - r:]
        A.sort(reverse=True)
        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 l in range(N + 1):
    for r in range(N + 1):
        if l + r > N:
            continue
        k = K - (l + r)
        if k < 0:
            continue

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

        A = V[:l] + V[N - r:]
        A.sort(reverse=True)
        while k > 0 and A and A[-1] < 0:
            A.pop()
            k -= 1
        ans = max(ans, sum(A)) r range(N + 1) range N + 1 N 1 if l + r > N:
            continue
         l + r > N l + r l r N continue k = K - (l + r) k K - (l + r) K l + r l r if k < 0:
            continue

         k < 0 k 0 continue A = V[:l] + V[N - r:] A V[:l] + V[N - r:] V[:l] V :l l V[N - r:] V N - r: N - r N r A.sort(reverse=True) A.sort A sort reverse=True reverse True 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 - (l + r) K - (l + r) k N, K = map(int, input().split()) map(int, input().split()) N ans = 0 0 ans A = V[:l] + V[N - r:] V[:l] + V[N - r:] A k -= 1 1 k K = map(int, input().split()) map(int, input().split()) K ans = max(ans, sum(A)) max(ans, sum(A)) ans V = list(map(int, input().split())) list(map(int, input().split())) V
N, K = map(int, input().split())
V = list(map(int, input().split()))

ans = 0
for l in range(N + 1):
    for r in range(N + 1):
        if l + r > N:
            continue
        k = K - (l + r)
        if k < 0:
            continue

        A = V[:l] + V[N - r:]
        A.sort(reverse=True)
        while k > 0 and A and A[-1] < 0:
            A.pop()
            k -= 1
        ans = max(ans, sum(A))
print(ans)
