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

V = [0] + list(map(int,input().split())) + [0]

m = min(N,K)



A = []

ans = 0



#左からi個、右からj個除いた時の宝石の価値のmax



for i in range(m+1):

    if i == 0:

        pass

    else:

        A.append(V[i])

    B = []

    for j in range(m-i+1):

        if j == 0:

            pass

        else:

            B.append(V[N-j+1])

        C = A+B

        C.sort()

        a = sum(C)

        for k in range(len(C)):

            if C[k] < 0 and k < K-(i+j):

                a -= C[k]

        ans = max(ans,a)



print(ans)
import sys



sys.setrecursionlimit(10**7)

def I(): return int(sys.stdin.readline().rstrip())

def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))

def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし

def S(): return sys.stdin.readline().rstrip()

def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり

def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし



N,K = MI()

V = LI()



ans = 0

for i in range(K+1):  # 操作回数

    for j in range(N+1):  # 左から

        for k in range(N+1):  # 右から

            if j + k > min(N,i):

                break

            l = i-j-k

            if l > j+k:

                continue

            A = [V[m] for m in range(j)] + [V[N-1-m] for m in range(k)]

            A.sort(reverse=True)

            ans = max(ans,sum(A[m] for m in range(j+k-l)))

print(ans)

N, K = list(map(int, input().split()))
V = [0] + list(map(int, input().split())) + [0]
m = min(N, K)
A = []
ans = 0
# 左からi個、右からj個除いた時の宝石の価値のmax
for i in range(m + 1):
    if i == 0:
        pass
    else:
        A.append(V[i])
    B = []
    for j in range(m - i + 1):
        if j == 0:
            pass
        else:
            B.append(V[N - j + 1])
        C = A + B
        C.sort()
        a = sum(C)
        for k in range(len(C)):
            if C[k] < 0 and k < K - (i + j):
                a -= C[k]
        ans = max(ans, a)
print(ans)

import sys

sys.setrecursionlimit(10**7)


def I():
    return int(sys.stdin.readline().rstrip())


def MI():
    return list(map(int, sys.stdin.readline().rstrip().split()))


def LI():
    return list(map(int, sys.stdin.readline().rstrip().split()))  # 空白あり


def LI2():
    return list(map(int, sys.stdin.readline().rstrip()))  # 空白なし


def S():
    return sys.stdin.readline().rstrip()


def LS():
    return list(sys.stdin.readline().rstrip().split())  # 空白あり


def LS2():
    return list(sys.stdin.readline().rstrip())  # 空白なし


N, K = MI()
V = LI()
ans = 0
for i in range(K + 1):  # 操作回数
    for j in range(N + 1):  # 左から
        for k in range(N + 1):  # 右から
            if j + k > min(N, i):
                break
            l = i - j - k
            if l > j + k:
                continue
            A = [V[m] for m in range(j)] + [V[N - 1 - m] for m in range(k)]
            A.sort(reverse=True)
            ans = max(ans, sum(A[m] for m in range(j + k - l)))
print(ans)

-N, K = list(map(int, input().split())) -V = [0] + list(map(int, input().split())) + [0] -m = min(N, K) -A = [] +import sys + +sys.setrecursionlimit(10**7) + + +def I(): +    return int(sys.stdin.readline().rstrip()) + + +def MI(): +    return list(map(int, sys.stdin.readline().rstrip().split())) + + +def LI(): +    return list(map(int, sys.stdin.readline().rstrip().split()))  # 空白あり + + +def LI2(): +    return list(map(int, sys.stdin.readline().rstrip()))  # 空白なし + + +def S(): +    return sys.stdin.readline().rstrip() + + +def LS(): +    return list(sys.stdin.readline().rstrip().split())  # 空白あり + + +def LS2(): +    return list(sys.stdin.readline().rstrip())  # 空白なし + + +N, K = MI() +V = LI() -# 左からi個、右からj個除いた時の宝石の価値のmax -for i in range(m + 1): -    if i == 0: -        pass -    else: -        A.append(V[i]) -    B = [] -    for j in range(m - i + 1): -        if j == 0: -            pass -        else: -            B.append(V[N - j + 1]) -        C = A + B -        C.sort() -        a = sum(C) -        for k in range(len(C)): -            if C[k] < 0 and k < K - (i + j): -                a -= C[k] -        ans = max(ans, a) +for i in range(K + 1):  # 操作回数 +    for j in range(N + 1):  # 左から +        for k in range(N + 1):  # 右から +            if j + k > min(N, i): +                break +            l = i - j - k +            if l > j + k: +                continue +            A = [V[m] for m in range(j)] + [V[N - 1 - m] for m in range(k)] +            A.sort(reverse=True) +            ans = max(ans, sum(A[m] for m in range(j + k - l)))