# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


inf = 10 ** 18
mod = 10 ** 9 + 7

n,k = lr()
v = lr()
v2 = [0]
for i in range(n):
    v2.append(v2[-1]+v[i])
def sumArea(l,r):
    return v2[r]-v2[l]
ans = -inf
for tmp in range(min(k,n)+1):
    for r in range(tmp+1):
        minus = []
        for num in v[:tmp-r]:
            if num < 0:
                minus.append(num)
        for num in v[n-r:]:
            if num < 0:
                minus.append(num)
        pre = sumArea(0,tmp-r) + sumArea(n-r,n)
        l = min(tmp,k-tmp,len(minus))
        if minus:
            minus.sort()
            pre -= sum(minus[:l])
        ans = max(ans,pre)
print(ans) import math math import fractions fractions import sys sys import bisect bisect import heapq heapq import collections collections from collections import Counter from collections import deque import pprint pprint sr = lambda: input() sr lambda: input() input() input 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を素因数分解""" """2以上の整数n => [[素因数, 指数], ...]の2次元リスト""" def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n factorization arr = [] arr [] temp = n temp n if n == 1:
        return arr

     n == 1 n 1 return arr arr for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

     i range(2, int(-(-n ** 0.5 // 1)) + 1) range 2 int(-(-n ** 0.5 // 1)) + 1 int(-(-n ** 0.5 // 1)) int -(-n ** 0.5 // 1) -n ** 0.5 // 1 -n ** 0.5 n ** 0.5 n 0.5 1 1 if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

     temp % i == 0 temp % i temp i 0 cnt = 0 cnt 0 while temp % i == 0:
                cnt += 1
                temp //= i
             temp % i == 0 temp % i temp i 0 cnt += 1 cnt 1 temp //= i temp i arr.append([i, cnt]) arr.append arr append [i, cnt] i cnt if temp != 1:
        arr.append([temp, 1])

     temp != 1 temp 1 arr.append([temp, 1]) arr.append arr append [temp, 1] temp 1 if arr == []:
        arr.append([n, 1])

     arr == [] arr [] arr.append([n, 1]) arr.append arr append [n, 1] n 1 return arr arr n n def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l power x = 1 x 1 while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
     n if n & 1:
            x *= a % mod
         n & 1 n 1 x *= a % mod x a % mod a mod n >>= 1 n 1 a *= a % mod a a % mod a mod return x % mod x % mod x mod a a n n mod mod def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a kaijo if n == 0:
        return 1
     n == 0 n 0 return 1 1 a = n a n tmp = n - 1 tmp n - 1 n 1 while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
     tmp >= l tmp l a = a * tmp % mod a a * tmp % mod a * tmp a tmp mod tmp -= 1 tmp 1 return a a n n l l mod mod inf = 10 ** 18 inf 10 ** 18 10 18 mod = 10 ** 9 + 7 mod 10 ** 9 + 7 10 ** 9 10 9 7 n,k = lr() n lr() lr k v = lr() v lr() lr v2 = [0] v2 [0] 0 for i in range(n):
    v2.append(v2[-1]+v[i]) i range(n) range n v2.append(v2[-1]+v[i]) v2.append v2 append v2[-1]+v[i] v2[-1] v2 -1 v[i] v i def sumArea(l,r):
    return v2[r]-v2[l] sumArea return v2[r]-v2[l] v2[r]-v2[l] v2[r] v2 r v2[l] v2 l l l r r ans = -inf ans -inf inf for tmp in range(min(k,n)+1):
    for r in range(tmp+1):
        minus = []
        for num in v[:tmp-r]:
            if num < 0:
                minus.append(num)
        for num in v[n-r:]:
            if num < 0:
                minus.append(num)
        pre = sumArea(0,tmp-r) + sumArea(n-r,n)
        l = min(tmp,k-tmp,len(minus))
        if minus:
            minus.sort()
            pre -= sum(minus[:l])
        ans = max(ans,pre) tmp range(min(k,n)+1) range min(k,n)+1 min(k,n) min k n 1 for r in range(tmp+1):
        minus = []
        for num in v[:tmp-r]:
            if num < 0:
                minus.append(num)
        for num in v[n-r:]:
            if num < 0:
                minus.append(num)
        pre = sumArea(0,tmp-r) + sumArea(n-r,n)
        l = min(tmp,k-tmp,len(minus))
        if minus:
            minus.sort()
            pre -= sum(minus[:l])
        ans = max(ans,pre) r range(tmp+1) range tmp+1 tmp 1 minus = [] minus [] for num in v[:tmp-r]:
            if num < 0:
                minus.append(num)
         num v[:tmp-r] v :tmp-r tmp-r tmp r if num < 0:
                minus.append(num)
         num < 0 num 0 minus.append(num) minus.append minus append num for num in v[n-r:]:
            if num < 0:
                minus.append(num)
         num v[n-r:] v n-r: n-r n r if num < 0:
                minus.append(num)
         num < 0 num 0 minus.append(num) minus.append minus append num pre = sumArea(0,tmp-r) + sumArea(n-r,n) pre sumArea(0,tmp-r) + sumArea(n-r,n) sumArea(0,tmp-r) sumArea 0 tmp-r tmp r sumArea(n-r,n) sumArea n-r n r n l = min(tmp,k-tmp,len(minus)) l min(tmp,k-tmp,len(minus)) min tmp k-tmp k tmp len(minus) len minus if minus:
            minus.sort()
            pre -= sum(minus[:l])
         minus minus.sort() minus.sort minus sort pre -= sum(minus[:l]) pre sum(minus[:l]) sum minus[:l] minus :l l ans = max(ans,pre) ans max(ans,pre) max ans pre print(ans) print ans inf = 10 ** 18 10 ** 18 inf def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n factorization pre = sumArea(0,tmp-r) + sumArea(n-r,n) sumArea(0,tmp-r) + sumArea(n-r,n) pre n,k = lr() lr() n pre -= sum(minus[:l]) sum(minus[:l]) pre def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a kaijo l = min(tmp,k-tmp,len(minus)) min(tmp,k-tmp,len(minus)) l lr = lambda: list(map(int, sr().split())) lambda: list(map(int, sr().split())) lr v2 = [0] [0] v2 ans = max(ans,pre) max(ans,pre) ans k = lr() lr() k def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l power mod = 10 ** 9 + 7 10 ** 9 + 7 mod v = lr() lr() v minus = [] [] minus ir = lambda: int(sr()) lambda: int(sr()) ir ans = -inf -inf ans def sumArea(l,r):
    return v2[r]-v2[l] def sumArea(l,r):
    return v2[r]-v2[l] sumArea sr = lambda: input() lambda: input() sr
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


inf = 10 ** 18
mod = 10 ** 9 + 7

n,k = lr()
v = lr()
v2 = [0]
for i in range(n):
    v2.append(v2[-1]+v[i])
def sumArea(l,r):
    return v2[r]-v2[l]
ans = -inf
for tmp in range(min(k,n)+1):
    for r in range(tmp+1):
        minus = []
        for num in v[:tmp-r]:
            if num < 0:
                minus.append(num)
        for num in v[n-r:]:
            if num < 0:
                minus.append(num)
        pre = sumArea(0,tmp-r) + sumArea(n-r,n)
        l = min(tmp,k-tmp,len(minus))
        if minus:
            minus.sort()
            pre -= sum(minus[:l])
        ans = max(ans,pre)
print(ans)