# 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()
answer = 0
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)
        if result > answer:
            answer = result
        for k in range(min(len(stone), K-(i+j))): # kは戻す個数
            if stone[k] > 0:
                break
            result -= stone[k] 
            if result > answer:
                answer = result

print(answer)
# 07 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 answer = 0 answer 0 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)
        if result > answer:
            answer = result
        for k in range(min(len(stone), K-(i+j))): # kは戻す個数
            if stone[k] > 0:
                break
            result -= stone[k] 
            if result > answer:
                answer = 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)
        if result > answer:
            answer = result
        for k in range(min(len(stone), K-(i+j))): # kは戻す個数
            if stone[k] > 0:
                break
            result -= stone[k] 
            if result > answer:
                answer = 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 if result > answer:
            answer = result
         result > answer result answer answer = result answer result for k in range(min(len(stone), K-(i+j))): # kは戻す個数
            if stone[k] > 0:
                break
            result -= stone[k] 
            if result > answer:
                answer = 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 if result > answer:
                answer = result result > answer result answer answer = result answer result print(answer) print answer stone = V[:i] + V[N-j:] V[:i] + V[N-j:] stone answer = result result answer answer = 0 0 answer result -= stone[k] stone[k] result N, K = lr() lr() N answer = result result answer lr = lambda: list(map(int, sr().split())) lambda: list(map(int, sr().split())) lr result = sum(stone) sum(stone) result ir = lambda: int(sr()) lambda: int(sr()) ir K = lr() lr() K V = lr() lr() V limit = min(N, K) min(N, K) limit sr = lambda: sys.stdin.readline().rstrip() lambda: sys.stdin.readline().rstrip() sr
# 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()
answer = 0
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)
        if result > answer:
            answer = result
        for k in range(min(len(stone), K-(i+j))): # kは戻す個数
            if stone[k] > 0:
                break
            result -= stone[k] 
            if result > answer:
                answer = result

print(answer)
# 07