import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations, combinations_with_replacement
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/abc128/tasks/abc128_d
N, K = read_ints()
V = read_ints()

ans = 0
for i, j in combinations_with_replacement(range(N + 1), r=2):
    # V[0:i]とV[j:]はとったことにしてみる
    k = i + (N - j)
    if k > K:
        continue
    Vsub = V[:i] + V[j:]
    # print(k)
    # print(Vsub)
    Vsub.sort(reverse=True)
    while Vsub and k < K and Vsub[-1] < 0:
        k += 1
        Vsub.pop()
    # print(Vsub)
    ans = max(sum(Vsub), ans)
print(ans) import sys sys sys.setrecursionlimit(1 << 25) sys.setrecursionlimit sys setrecursionlimit 1 << 25 1 25 read = sys.stdin.readline read sys.stdin.readline sys.stdin sys stdin readline ra = range ra range enu = enumerate enu enumerate def read_ints():
    return list(map(int, read().split())) read_ints return list(map(int, read().split())) list(map(int, read().split())) list map(int, read().split()) map int read().split() ().split () read split def read_a_int():
    return int(read()) read_a_int return int(read()) int(read()) int read() read def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret read_tuple '''
    H is number of rows
    ''' ret = [] ret [] for _ in range(H):
        ret.append(tuple(map(int, read().split())))
     _ range(H) range H ret.append(tuple(map(int, read().split()))) ret.append ret append tuple(map(int, read().split())) tuple map(int, read().split()) map int read().split() ().split () read split return ret ret H H def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret))) read_col '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    ''' ret = [] ret [] for _ in range(H):
        ret.append(list(map(int, read().split())))
     _ range(H) range H ret.append(list(map(int, read().split()))) ret.append ret append list(map(int, read().split())) list map(int, read().split()) map int read().split() ().split () read split return tuple(map(list, zip(*ret))) tuple(map(list, zip(*ret))) tuple map(list, zip(*ret)) map list zip(*ret) zip *ret ret H H def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため read_matrix '''
    H is number of rows
    ''' ret = [] ret [] for _ in range(H):
        ret.append(list(map(int, read().split())))
     _ range(H) range H ret.append(list(map(int, read().split()))) ret.append ret append list(map(int, read().split())) list map(int, read().split()) map int read().split() ().split () read split return ret ret H H MOD = 10**9 + 7 MOD 10**9 + 7 10**9 10 9 7 INF = 2**31 INF 2**31 2 31 from collections import defaultdict, Counter, deque from operator import itemgetter from itertools import product, permutations, combinations, combinations_with_replacement from bisect import bisect_left, bisect_right N, K = read_ints() N read_ints() read_ints K V = read_ints() V read_ints() read_ints ans = 0 ans 0 for i, j in combinations_with_replacement(range(N + 1), r=2):
    # V[0:i]とV[j:]はとったことにしてみる
    k = i + (N - j)
    if k > K:
        continue
    Vsub = V[:i] + V[j:]
    # print(k)
    # print(Vsub)
    Vsub.sort(reverse=True)
    while Vsub and k < K and Vsub[-1] < 0:
        k += 1
        Vsub.pop()
    # print(Vsub)
    ans = max(sum(Vsub), ans) i j combinations_with_replacement(range(N + 1), r=2) combinations_with_replacement range(N + 1) range N + 1 N 1 r=2 r 2 k = i + (N - j) k i + (N - j) i N - j N j if k > K:
        continue
     k > K k K continue Vsub = V[:i] + V[j:] Vsub V[:i] + V[j:] V[:i] V :i i V[j:] V j: j Vsub.sort(reverse=True) Vsub.sort Vsub sort reverse=True reverse True while Vsub and k < K and Vsub[-1] < 0:
        k += 1
        Vsub.pop()
    # print(Vsub)
     Vsub and k < K and Vsub[-1] < 0 Vsub and k < K Vsub k < K k K Vsub[-1] < 0 Vsub[-1] Vsub -1 0 k += 1 k 1 Vsub.pop() Vsub.pop Vsub pop ans = max(sum(Vsub), ans) ans max(sum(Vsub), ans) max sum(Vsub) sum Vsub ans print(ans) print ans INF = 2**31 2**31 INF enu = enumerate enumerate enu ra = range range ra def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため read_matrix def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret read_tuple k = i + (N - j) i + (N - j) k Vsub = V[:i] + V[j:] V[:i] + V[j:] Vsub K = read_ints() read_ints() K k += 1 1 k ans = max(sum(Vsub), ans) max(sum(Vsub), ans) ans def read_ints():
    return list(map(int, read().split())) def read_ints():
    return list(map(int, read().split())) read_ints V = read_ints() read_ints() V ans = 0 0 ans N, K = read_ints() read_ints() N read = sys.stdin.readline sys.stdin.readline read def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret))) def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret))) read_col def read_a_int():
    return int(read()) def read_a_int():
    return int(read()) read_a_int MOD = 10**9 + 7 10**9 + 7 MOD
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations, combinations_with_replacement
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/abc128/tasks/abc128_d
N, K = read_ints()
V = read_ints()

ans = 0
for i, j in combinations_with_replacement(range(N + 1), r=2):
    # V[0:i]とV[j:]はとったことにしてみる
    k = i + (N - j)
    if k > K:
        continue
    Vsub = V[:i] + V[j:]
    # print(k)
    # print(Vsub)
    Vsub.sort(reverse=True)
    while Vsub and k < K and Vsub[-1] < 0:
        k += 1
        Vsub.pop()
    # print(Vsub)
    ans = max(sum(Vsub), ans)
print(ans)
