import bisect


n, k = map(int, input().split())
v = list(map(int, input().split()))

res = 0
for toru in range(0, min(k, n) + 1):
    tumeru = k - toru
    for migi in range(0, toru + 1):
        hidari = toru - migi
        ans = v[0:hidari] + v[n - migi:n]        
        ans = sorted(ans)
        ind = bisect.bisect_left(ans, 0)
        res = max((sum(ans) - sum(ans[0:min(ind, tumeru)])), res)
print(res)  import bisect bisect n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k v = list(map(int, input().split())) v list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split res = 0 res 0 for toru in range(0, min(k, n) + 1):
    tumeru = k - toru
    for migi in range(0, toru + 1):
        hidari = toru - migi
        ans = v[0:hidari] + v[n - migi:n]        
        ans = sorted(ans)
        ind = bisect.bisect_left(ans, 0)
        res = max((sum(ans) - sum(ans[0:min(ind, tumeru)])), res) toru range(0, min(k, n) + 1) range 0 min(k, n) + 1 min(k, n) min k n 1 tumeru = k - toru tumeru k - toru k toru for migi in range(0, toru + 1):
        hidari = toru - migi
        ans = v[0:hidari] + v[n - migi:n]        
        ans = sorted(ans)
        ind = bisect.bisect_left(ans, 0)
        res = max((sum(ans) - sum(ans[0:min(ind, tumeru)])), res) migi range(0, toru + 1) range 0 toru + 1 toru 1 hidari = toru - migi hidari toru - migi toru migi ans = v[0:hidari] + v[n - migi:n] ans v[0:hidari] + v[n - migi:n] v[0:hidari] v 0:hidari 0 hidari v[n - migi:n] v n - migi:n n - migi n migi n ans = sorted(ans) ans sorted(ans) sorted ans ind = bisect.bisect_left(ans, 0) ind bisect.bisect_left(ans, 0) bisect.bisect_left bisect bisect_left ans 0 res = max((sum(ans) - sum(ans[0:min(ind, tumeru)])), res) res max((sum(ans) - sum(ans[0:min(ind, tumeru)])), res) max sum(ans) - sum(ans[0:min(ind, tumeru)]) sum(ans) sum ans sum(ans[0:min(ind, tumeru)]) sum ans[0:min(ind, tumeru)] ans 0:min(ind, tumeru) 0 min(ind, tumeru) min ind tumeru res print(res) print res v = list(map(int, input().split())) list(map(int, input().split())) v res = 0 0 res res = max((sum(ans) - sum(ans[0:min(ind, tumeru)])), res) max((sum(ans) - sum(ans[0:min(ind, tumeru)])), res) res ans = v[0:hidari] + v[n - migi:n] v[0:hidari] + v[n - migi:n] ans ans = sorted(ans) sorted(ans) ans n, k = map(int, input().split()) map(int, input().split()) n hidari = toru - migi toru - migi hidari k = map(int, input().split()) map(int, input().split()) k ind = bisect.bisect_left(ans, 0) bisect.bisect_left(ans, 0) ind tumeru = k - toru k - toru tumeru
import bisect


n, k = map(int, input().split())
v = list(map(int, input().split()))

res = 0
for toru in range(0, min(k, n) + 1):
    tumeru = k - toru
    for migi in range(0, toru + 1):
        hidari = toru - migi
        ans = v[0:hidari] + v[n - migi:n]        
        ans = sorted(ans)
        ind = bisect.bisect_left(ans, 0)
        res = max((sum(ans) - sum(ans[0:min(ind, tumeru)])), res)
print(res) 