N, K = map(int, input().split())
X = list(map(int, input().split()))
r = -10**18
for i in range(-1, N):
#    print(i)
    for j in range(i+1, N+1):
        A, B = X[:i+1], X[j:]
        if i+1+N-j > K:
            continue
        C = sorted(A+B)[::-1]
#        print(A, B, i+1, N-j, i, j)
        for _ in range(K-(i+1+N-j)):
            if not C:
                break
            c = C.pop()
            if c > 0:
                C.append(c)
                break
        r = max(r, sum(C))
print(r) N, K = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split K X = list(map(int, input().split())) X list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split r = -10**18 r -10**18 -10 18 for i in range(-1, N):
#    print(i)
    for j in range(i+1, N+1):
        A, B = X[:i+1], X[j:]
        if i+1+N-j > K:
            continue
        C = sorted(A+B)[::-1]
#        print(A, B, i+1, N-j, i, j)
        for _ in range(K-(i+1+N-j)):
            if not C:
                break
            c = C.pop()
            if c > 0:
                C.append(c)
                break
        r = max(r, sum(C)) i range(-1, N) range -1 N for j in range(i+1, N+1):
        A, B = X[:i+1], X[j:]
        if i+1+N-j > K:
            continue
        C = sorted(A+B)[::-1]
#        print(A, B, i+1, N-j, i, j)
        for _ in range(K-(i+1+N-j)):
            if not C:
                break
            c = C.pop()
            if c > 0:
                C.append(c)
                break
        r = max(r, sum(C)) j range(i+1, N+1) range i+1 i 1 N+1 N 1 A, B = X[:i+1], X[j:] A X[:i+1] X :i+1 i+1 i 1 B X[j:] X j: j if i+1+N-j > K:
            continue
         i+1+N-j > K i+1+N-j i+1+N i+1 i 1 N j K continue C = sorted(A+B)[::-1] C sorted(A+B)[::-1] (A+B) sorted A+B A B ::-1 -1 for _ in range(K-(i+1+N-j)):
            if not C:
                break
            c = C.pop()
            if c > 0:
                C.append(c)
                break
         _ range(K-(i+1+N-j)) range K-(i+1+N-j) K i+1+N-j i+1+N i+1 i 1 N j if not C:
                break
             not C C break c = C.pop() c C.pop() C.pop C pop if c > 0:
                C.append(c)
                break
         c > 0 c 0 C.append(c) C.append C append c break r = max(r, sum(C)) r max(r, sum(C)) max r sum(C) sum C print(r) print r r = max(r, sum(C)) max(r, sum(C)) r N, K = map(int, input().split()) map(int, input().split()) N B = X[:i+1], X[j:] X[j:] B X = list(map(int, input().split())) list(map(int, input().split())) X r = -10**18 -10**18 r c = C.pop() C.pop() c K = map(int, input().split()) map(int, input().split()) K A, B = X[:i+1], X[j:] X[:i+1] A C = sorted(A+B)[::-1] sorted(A+B)[::-1] C
N, K = map(int, input().split())
X = list(map(int, input().split()))
r = -10**18
for i in range(-1, N):
#    print(i)
    for j in range(i+1, N+1):
        A, B = X[:i+1], X[j:]
        if i+1+N-j > K:
            continue
        C = sorted(A+B)[::-1]
#        print(A, B, i+1, N-j, i, j)
        for _ in range(K-(i+1+N-j)):
            if not C:
                break
            c = C.pop()
            if c > 0:
                C.append(c)
                break
        r = max(r, sum(C))
print(r)
