from bisect import bisect_left as bil
N, K, *V = map(int, open(0).read().split())


k = min(N, K)
ans = 0
for i in range(k+1):
    for j in range(k-i+1):
        U = V[:i]+V[-j:] if j != 0 else V[:i]
        U.sort()
        z = min(bil(U, 0), K-i-j)
        sm = sum(U[z:])

        if ans < sm:
            ans = sm

print(ans) from bisect import bisect_left as bil N, K, *V = map(int, open(0).read().split()) N map(int, open(0).read().split()) map int open(0).read().split() (0).read().split (0).read() (0).read (0) open 0 read split K *V V k = min(N, K) k min(N, K) min N K ans = 0 ans 0 for i in range(k+1):
    for j in range(k-i+1):
        U = V[:i]+V[-j:] if j != 0 else V[:i]
        U.sort()
        z = min(bil(U, 0), K-i-j)
        sm = sum(U[z:])

        if ans < sm:
            ans = sm i range(k+1) range k+1 k 1 for j in range(k-i+1):
        U = V[:i]+V[-j:] if j != 0 else V[:i]
        U.sort()
        z = min(bil(U, 0), K-i-j)
        sm = sum(U[z:])

        if ans < sm:
            ans = sm j range(k-i+1) range k-i+1 k-i k i 1 U = V[:i]+V[-j:] if j != 0 else V[:i] U V[:i]+V[-j:] if j != 0 else V[:i] j != 0 j 0 V[:i]+V[-j:] V[:i] V :i i V[-j:] V -j: -j j V[:i] V :i i U.sort() U.sort U sort z = min(bil(U, 0), K-i-j) z min(bil(U, 0), K-i-j) min bil(U, 0) bil U 0 K-i-j K-i K i j sm = sum(U[z:]) sm sum(U[z:]) sum U[z:] U z: z if ans < sm:
            ans = sm ans < sm ans sm ans = sm ans sm print(ans) print ans N, K, *V = map(int, open(0).read().split()) map(int, open(0).read().split()) N ans = 0 0 ans K, *V = map(int, open(0).read().split()) map(int, open(0).read().split()) K k = min(N, K) min(N, K) k U = V[:i]+V[-j:] if j != 0 else V[:i] V[:i]+V[-j:] if j != 0 else V[:i] U ans = sm sm ans z = min(bil(U, 0), K-i-j) min(bil(U, 0), K-i-j) z sm = sum(U[z:]) sum(U[z:]) sm
from bisect import bisect_left as bil
N, K, *V = map(int, open(0).read().split())


k = min(N, K)
ans = 0
for i in range(k+1):
    for j in range(k-i+1):
        U = V[:i]+V[-j:] if j != 0 else V[:i]
        U.sort()
        z = min(bil(U, 0), K-i-j)
        sm = sum(U[z:])

        if ans < sm:
            ans = sm

print(ans)
