# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
V = lr()
scores = set()
limit = min(N, K)
for i in range(limit+1): # iは左から取り出す個数
    for j in range(limit-i+1): # jは右から取り出す個数
        stone = V[:i] + V[N-j:]
        stone.sort()
        result = sum(stone)
        scores.add(result)
        for k in range(min(len(stone), K-(i+j))): # kは戻す個数
            if stone[k] >= 0:
                break
            result -= stone[k]
            scores.add(result)

answer = max(scores)
print(answer)
# import sys sys sr = lambda: sys.stdin.readline().rstrip() sr lambda: sys.stdin.readline().rstrip() sys.stdin.readline().rstrip() sys.stdin.readline().rstrip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline rstrip ir = lambda: int(sr()) ir lambda: int(sr()) int(sr()) int sr() sr lr = lambda: list(map(int, sr().split())) lr lambda: list(map(int, sr().split())) list(map(int, sr().split())) list map(int, sr().split()) map int sr().split() ().split () sr split N, K = lr() N lr() lr K V = lr() V lr() lr scores = set() scores set() set limit = min(N, K) limit min(N, K) min N K for i in range(limit+1): # iは左から取り出す個数
    for j in range(limit-i+1): # jは右から取り出す個数
        stone = V[:i] + V[N-j:]
        stone.sort()
        result = sum(stone)
        scores.add(result)
        for k in range(min(len(stone), K-(i+j))): # kは戻す個数
            if stone[k] >= 0:
                break
            result -= stone[k]
            scores.add(result) i range(limit+1) range limit+1 limit 1 for j in range(limit-i+1): # jは右から取り出す個数
        stone = V[:i] + V[N-j:]
        stone.sort()
        result = sum(stone)
        scores.add(result)
        for k in range(min(len(stone), K-(i+j))): # kは戻す個数
            if stone[k] >= 0:
                break
            result -= stone[k]
            scores.add(result) j range(limit-i+1) range limit-i+1 limit-i limit i 1 stone = V[:i] + V[N-j:] stone V[:i] + V[N-j:] V[:i] V :i i V[N-j:] V N-j: N-j N j stone.sort() stone.sort stone sort result = sum(stone) result sum(stone) sum stone scores.add(result) scores.add scores add result for k in range(min(len(stone), K-(i+j))): # kは戻す個数
            if stone[k] >= 0:
                break
            result -= stone[k]
            scores.add(result) k range(min(len(stone), K-(i+j))) range min(len(stone), K-(i+j)) min len(stone) len stone K-(i+j) K i+j i j if stone[k] >= 0:
                break
             stone[k] >= 0 stone[k] stone k 0 break result -= stone[k] result stone[k] stone k scores.add(result) scores.add scores add result answer = max(scores) answer max(scores) max scores print(answer) print answer V = lr() lr() V lr = lambda: list(map(int, sr().split())) lambda: list(map(int, sr().split())) lr scores = set() set() scores result -= stone[k] stone[k] result answer = max(scores) max(scores) answer sr = lambda: sys.stdin.readline().rstrip() lambda: sys.stdin.readline().rstrip() sr stone = V[:i] + V[N-j:] V[:i] + V[N-j:] stone N, K = lr() lr() N K = lr() lr() K limit = min(N, K) min(N, K) limit result = sum(stone) sum(stone) result ir = lambda: int(sr()) lambda: int(sr()) ir
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
V = lr()
scores = set()
limit = min(N, K)
for i in range(limit+1): # iは左から取り出す個数
    for j in range(limit-i+1): # jは右から取り出す個数
        stone = V[:i] + V[N-j:]
        stone.sort()
        result = sum(stone)
        scores.add(result)
        for k in range(min(len(stone), K-(i+j))): # kは戻す個数
            if stone[k] >= 0:
                break
            result -= stone[k]
            scores.add(result)

answer = max(scores)
print(answer)
#