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

ans = 0
for left in range(min(N, K) + 1):
    for right in range(min(N - left, K - left) + 1):
        tmp = V[:left] + V[N - right:]
        tmp.sort()
        score = 0
        count = K - left - right
        for i in tmp:
            if count <= 0:
                score += i
            else:
                if i < 0:
                    count -= 1
                else:
                    score += i
        # print (left, right, score, tmp)
        ans = max(ans, score)

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(min(N, K) + 1):
    for right in range(min(N - left, K - left) + 1):
        tmp = V[:left] + V[N - right:]
        tmp.sort()
        score = 0
        count = K - left - right
        for i in tmp:
            if count <= 0:
                score += i
            else:
                if i < 0:
                    count -= 1
                else:
                    score += i
        # print (left, right, score, tmp)
        ans = max(ans, score) left range(min(N, K) + 1) range min(N, K) + 1 min(N, K) min N K 1 for right in range(min(N - left, K - left) + 1):
        tmp = V[:left] + V[N - right:]
        tmp.sort()
        score = 0
        count = K - left - right
        for i in tmp:
            if count <= 0:
                score += i
            else:
                if i < 0:
                    count -= 1
                else:
                    score += i
        # print (left, right, score, tmp)
        ans = max(ans, score) right range(min(N - left, K - left) + 1) range min(N - left, K - left) + 1 min(N - left, K - left) min N - left N left K - left K left 1 tmp = V[:left] + V[N - right:] tmp V[:left] + V[N - right:] V[:left] V :left left V[N - right:] V N - right: N - right N right tmp.sort() tmp.sort tmp sort score = 0 score 0 count = K - left - right count K - left - right K - left K left right for i in tmp:
            if count <= 0:
                score += i
            else:
                if i < 0:
                    count -= 1
                else:
                    score += i
        # print (left, right, score, tmp)
         i tmp if count <= 0:
                score += i
            else:
                if i < 0:
                    count -= 1
                else:
                    score += i
        # print (left, right, score, tmp)
         count <= 0 count 0 score += i score i if i < 0:
                    count -= 1
                else:
                    score += i
        # print (left, right, score, tmp)
         i < 0 i 0 count -= 1 count 1 score += i score i ans = max(ans, score) ans max(ans, score) max ans score print (ans) print ans count = K - left - right K - left - right count V = list(map(int, input().split())) list(map(int, input().split())) V count -= 1 1 count N, K = map(int, input().split()) map(int, input().split()) N ans = max(ans, score) max(ans, score) ans ans = 0 0 ans tmp = V[:left] + V[N - right:] V[:left] + V[N - right:] tmp score += i i score score = 0 0 score K = map(int, input().split()) map(int, input().split()) K score += i i score
N, K = map(int, input().split())
V = list(map(int, input().split()))

ans = 0
for left in range(min(N, K) + 1):
    for right in range(min(N - left, K - left) + 1):
        tmp = V[:left] + V[N - right:]
        tmp.sort()
        score = 0
        count = K - left - right
        for i in tmp:
            if count <= 0:
                score += i
            else:
                if i < 0:
                    count -= 1
                else:
                    score += i
        # print (left, right, score, tmp)
        ans = max(ans, score)

print (ans)