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

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) import sys sys def MI(): return map(int,sys.stdin.readline().rstrip().split()) MI def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり LI N,K = MI() N MI() MI K V = LI() V LI() LI ans = 0 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))) i range(K+1) range K+1 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))) j range(N+1) range N+1 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))) k range(N+1) range N+1 N 1 if j + k > min(N,i):
                break
             j + k > min(N,i) j + k j k min(N,i) min N i break l = i-j-k l i-j-k i-j i j k if l > j+k:
                continue
             l > j+k l j+k j k continue V[m] for m in range(j) for m in range(j) m range(j) range j for m in range(j) V[m] V m A = [V[m] for m in range(j)] + [V[N-1-m] for m in range(k)] A [V[m] for m in range(j)] + [V[N-1-m] for m in range(k)] [V[m] for m in range(j)] [V[N-1-m] for m in range(k)] A.sort(reverse=True) A.sort A sort reverse=True reverse True ans = max(ans,sum(A[m] for m in range(j+k-l))) ans max(ans,sum(A[m] for m in range(j+k-l))) max ans sum(A[m] for m in range(j+k-l)) sum A[m] A m print(ans) print ans N,K = MI() MI() N def MI(): return map(int,sys.stdin.readline().rstrip().split()) def MI(): return map(int,sys.stdin.readline().rstrip().split()) MI ans = 0 0 ans l = i-j-k i-j-k l A = [V[m] for m in range(j)] + [V[N-1-m] for m in range(k)] [V[m] for m in range(j)] + [V[N-1-m] for m in range(k)] A def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり LI K = MI() MI() K V = LI() LI() V ans = max(ans,sum(A[m] for m in range(j+k-l))) max(ans,sum(A[m] for m in range(j+k-l))) ans
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

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)
