n, k = [int(x) for x in input().split()]
v_list = [int(x) for x in input().split()]

stop = min(n, k)

ans = 0
for a in range(stop + 1):
    a_list = v_list[:a]
    for b in range(stop + 1 - a):
        b_list = v_list[n-b:]
    
        temp_list = a_list + b_list
        temp_list.sort(reverse=True)

        for _ in range(k - a - b):
            if len(temp_list) == 0 or temp_list[-1] >= 0:
                break
            temp_list.pop()

        temp = sum(temp_list)
        if ans < temp:
            ans = temp
print(ans) int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x n, k = [int(x) for x in input().split()] n [int(x) for x in input().split()] k int(x) for x in input().split() for x in input().split() x input().split() ().split () input split for x in input().split() int(x) int x v_list = [int(x) for x in input().split()] v_list [int(x) for x in input().split()] stop = min(n, k) stop min(n, k) min n k ans = 0 ans 0 for a in range(stop + 1):
    a_list = v_list[:a]
    for b in range(stop + 1 - a):
        b_list = v_list[n-b:]
    
        temp_list = a_list + b_list
        temp_list.sort(reverse=True)

        for _ in range(k - a - b):
            if len(temp_list) == 0 or temp_list[-1] >= 0:
                break
            temp_list.pop()

        temp = sum(temp_list)
        if ans < temp:
            ans = temp a range(stop + 1) range stop + 1 stop 1 a_list = v_list[:a] a_list v_list[:a] v_list :a a for b in range(stop + 1 - a):
        b_list = v_list[n-b:]
    
        temp_list = a_list + b_list
        temp_list.sort(reverse=True)

        for _ in range(k - a - b):
            if len(temp_list) == 0 or temp_list[-1] >= 0:
                break
            temp_list.pop()

        temp = sum(temp_list)
        if ans < temp:
            ans = temp b range(stop + 1 - a) range stop + 1 - a stop + 1 stop 1 a b_list = v_list[n-b:] b_list v_list[n-b:] v_list n-b: n-b n b temp_list = a_list + b_list temp_list a_list + b_list a_list b_list temp_list.sort(reverse=True) temp_list.sort temp_list sort reverse=True reverse True for _ in range(k - a - b):
            if len(temp_list) == 0 or temp_list[-1] >= 0:
                break
            temp_list.pop()

         _ range(k - a - b) range k - a - b k - a k a b if len(temp_list) == 0 or temp_list[-1] >= 0:
                break
             len(temp_list) == 0 or temp_list[-1] >= 0 len(temp_list) == 0 len(temp_list) len temp_list 0 temp_list[-1] >= 0 temp_list[-1] temp_list -1 0 break temp_list.pop() temp_list.pop temp_list pop temp = sum(temp_list) temp sum(temp_list) sum temp_list if ans < temp:
            ans = temp ans < temp ans temp ans = temp ans temp print(ans) print ans ans = 0 0 ans temp = sum(temp_list) sum(temp_list) temp n, k = [int(x) for x in input().split()] [int(x) for x in input().split()] n stop = min(n, k) min(n, k) stop ans = temp temp ans a_list = v_list[:a] v_list[:a] a_list k = [int(x) for x in input().split()] [int(x) for x in input().split()] k v_list = [int(x) for x in input().split()] [int(x) for x in input().split()] v_list b_list = v_list[n-b:] v_list[n-b:] b_list temp_list = a_list + b_list a_list + b_list temp_list
n, k = [int(x) for x in input().split()]
v_list = [int(x) for x in input().split()]

stop = min(n, k)

ans = 0
for a in range(stop + 1):
    a_list = v_list[:a]
    for b in range(stop + 1 - a):
        b_list = v_list[n-b:]
    
        temp_list = a_list + b_list
        temp_list.sort(reverse=True)

        for _ in range(k - a - b):
            if len(temp_list) == 0 or temp_list[-1] >= 0:
                break
            temp_list.pop()

        temp = sum(temp_list)
        if ans < temp:
            ans = temp
print(ans)