import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate

def solve():
    N, K = MI()
    V = LI()
    max_iter = min(N, K)
    ans = 0
    for a in range(max_iter+1):
        left = V[:a]
        for b in range(0, max_iter-a+1):
            right = V[-b:] if b != 0 else []
            k = K - a - b
            # print(a, b, k)
            # print(left, right)
            lst = sorted(left + right)
            # print(lst)
            sm = sum(lst)
            l = len(lst)
            for kk in range(1, k+1):
                if kk < l:
                    tmp = lst[kk-1]
                    if tmp >= 0: break
                    sm -= tmp
                    # print(tmp)
                else:
                    break
            ans = max(ans, sm)
    print(ans)


if __name__ == '__main__':
    solve() import sys sys sys.setrecursionlimit(10 ** 9) sys.setrecursionlimit sys setrecursionlimit 10 ** 9 10 9 def int1(x): return int(x) - 1 int1 x x def II(): return int(input()) II def MI(): return map(int, input().split()) MI def MI1(): return map(int1, input().split()) MI1 def LI(): return list(map(int, input().split())) LI def LI1(): return list(map(int1, input().split())) LI1 LI() for _ in range(rows_number) for _ in range(rows_number) _ range(rows_number) range rows_number for _ in range(rows_number) LI() LI def LLI(rows_number): return [LI() for _ in range(rows_number)] LLI rows_number rows_number def MS(): return input().split() MS def LS(): return list(input()) LS LS() for _ in range(rows_number) for _ in range(rows_number) _ range(rows_number) range rows_number for _ in range(rows_number) LS() LS def LLS(rows_number): return [LS() for _ in range(rows_number)] LLS rows_number rows_number def printlist(lst, k=' '): print(k.join(list(map(str, lst)))) printlist lst lst k=' ' k ' ' INF = float('inf') INF float('inf') float 'inf' from collections import deque from heapq import heapify, heappop, heappush def solve():
    N, K = MI()
    V = LI()
    max_iter = min(N, K)
    ans = 0
    for a in range(max_iter+1):
        left = V[:a]
        for b in range(0, max_iter-a+1):
            right = V[-b:] if b != 0 else []
            k = K - a - b
            # print(a, b, k)
            # print(left, right)
            lst = sorted(left + right)
            # print(lst)
            sm = sum(lst)
            l = len(lst)
            for kk in range(1, k+1):
                if kk < l:
                    tmp = lst[kk-1]
                    if tmp >= 0: break
                    sm -= tmp
                    # print(tmp)
                else:
                    break
            ans = max(ans, sm)
    print(ans) solve N, K = MI() N MI() MI K V = LI() V LI() LI max_iter = min(N, K) max_iter min(N, K) min N K ans = 0 ans 0 for a in range(max_iter+1):
        left = V[:a]
        for b in range(0, max_iter-a+1):
            right = V[-b:] if b != 0 else []
            k = K - a - b
            # print(a, b, k)
            # print(left, right)
            lst = sorted(left + right)
            # print(lst)
            sm = sum(lst)
            l = len(lst)
            for kk in range(1, k+1):
                if kk < l:
                    tmp = lst[kk-1]
                    if tmp >= 0: break
                    sm -= tmp
                    # print(tmp)
                else:
                    break
            ans = max(ans, sm)
     a range(max_iter+1) range max_iter+1 max_iter 1 left = V[:a] left V[:a] V :a a for b in range(0, max_iter-a+1):
            right = V[-b:] if b != 0 else []
            k = K - a - b
            # print(a, b, k)
            # print(left, right)
            lst = sorted(left + right)
            # print(lst)
            sm = sum(lst)
            l = len(lst)
            for kk in range(1, k+1):
                if kk < l:
                    tmp = lst[kk-1]
                    if tmp >= 0: break
                    sm -= tmp
                    # print(tmp)
                else:
                    break
            ans = max(ans, sm)
     b range(0, max_iter-a+1) range 0 max_iter-a+1 max_iter-a max_iter a 1 right = V[-b:] if b != 0 else [] right V[-b:] if b != 0 else [] b != 0 b 0 V[-b:] V -b: -b b [] k = K - a - b k K - a - b K - a K a b lst = sorted(left + right) lst sorted(left + right) sorted left + right left right sm = sum(lst) sm sum(lst) sum lst l = len(lst) l len(lst) len lst for kk in range(1, k+1):
                if kk < l:
                    tmp = lst[kk-1]
                    if tmp >= 0: break
                    sm -= tmp
                    # print(tmp)
                else:
                    break
             kk range(1, k+1) range 1 k+1 k 1 if kk < l:
                    tmp = lst[kk-1]
                    if tmp >= 0: break
                    sm -= tmp
                    # print(tmp)
                else:
                    break
             kk < l kk l tmp = lst[kk-1] tmp lst[kk-1] lst kk-1 kk 1 if tmp >= 0: break
                     tmp >= 0 tmp 0 sm -= tmp sm tmp break ans = max(ans, sm) ans max(ans, sm) max ans sm print(ans) print ans if __name__ == '__main__':
    solve() __name__ == '__main__' __name__ '__main__' solve() solve def int1(x): return int(x) - 1 def int1(x): return int(x) - 1 int1 def LLI(rows_number): return [LI() for _ in range(rows_number)] def LLI(rows_number): return [LI() for _ in range(rows_number)] LLI def MI1(): return map(int1, input().split()) def MI1(): return map(int1, input().split()) MI1 def LS(): return list(input()) def LS(): return list(input()) LS def II(): return int(input()) def II(): return int(input()) II def MS(): return input().split() def MS(): return input().split() MS def LLS(rows_number): return [LS() for _ in range(rows_number)] def LLS(rows_number): return [LS() for _ in range(rows_number)] LLS INF = float('inf') float('inf') INF def printlist(lst, k=' '): print(k.join(list(map(str, lst)))) def printlist(lst, k=' '): print(k.join(list(map(str, lst)))) printlist def solve():
    N, K = MI()
    V = LI()
    max_iter = min(N, K)
    ans = 0
    for a in range(max_iter+1):
        left = V[:a]
        for b in range(0, max_iter-a+1):
            right = V[-b:] if b != 0 else []
            k = K - a - b
            # print(a, b, k)
            # print(left, right)
            lst = sorted(left + right)
            # print(lst)
            sm = sum(lst)
            l = len(lst)
            for kk in range(1, k+1):
                if kk < l:
                    tmp = lst[kk-1]
                    if tmp >= 0: break
                    sm -= tmp
                    # print(tmp)
                else:
                    break
            ans = max(ans, sm)
    print(ans) def solve():
    N, K = MI()
    V = LI()
    max_iter = min(N, K)
    ans = 0
    for a in range(max_iter+1):
        left = V[:a]
        for b in range(0, max_iter-a+1):
            right = V[-b:] if b != 0 else []
            k = K - a - b
            # print(a, b, k)
            # print(left, right)
            lst = sorted(left + right)
            # print(lst)
            sm = sum(lst)
            l = len(lst)
            for kk in range(1, k+1):
                if kk < l:
                    tmp = lst[kk-1]
                    if tmp >= 0: break
                    sm -= tmp
                    # print(tmp)
                else:
                    break
            ans = max(ans, sm)
    print(ans) solve def MI(): return map(int, input().split()) def MI(): return map(int, input().split()) MI def LI1(): return list(map(int1, input().split())) def LI1(): return list(map(int1, input().split())) LI1 def LI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) LI
import sys
sys.setrecursionlimit(10 ** 9)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
# from math import ceil, floor, log2
from collections import deque
# from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product, permutations
from heapq import heapify, heappop, heappush
# import numpy as np
# from numpy import cumsum  # accumulate

def solve():
    N, K = MI()
    V = LI()
    max_iter = min(N, K)
    ans = 0
    for a in range(max_iter+1):
        left = V[:a]
        for b in range(0, max_iter-a+1):
            right = V[-b:] if b != 0 else []
            k = K - a - b
            # print(a, b, k)
            # print(left, right)
            lst = sorted(left + right)
            # print(lst)
            sm = sum(lst)
            l = len(lst)
            for kk in range(1, k+1):
                if kk < l:
                    tmp = lst[kk-1]
                    if tmp >= 0: break
                    sm -= tmp
                    # print(tmp)
                else:
                    break
            ans = max(ans, sm)
    print(ans)


if __name__ == '__main__':
    solve()
