# -*- coding: utf-8 -*-
#D - equeue
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, K = map(int, readline().split())
V = list(map(int,readline().split()))

ans = 0
for l in range(min(K,N)+1):
    for r in range(min(K,N)-l+1):
        res = K - (l+r)
        minus = [] 
        total = sum(V[:l])+sum(V[N-r:])
        for i in range(l):
            if V[i] < 0:
                minus.append(V[i])        
        for i in range(r):
            if V[-i-1] < 0:
                minus.append(V[-i-1])
        minus.sort()
        S = len(minus)
        rep = sum(minus[:min(S+1,res)])
        total -= rep
        # print(l,r,total,rep)
        ans = max(total,ans)
print(ans)  import sys sys read = sys.stdin.buffer.read read sys.stdin.buffer.read sys.stdin.buffer sys.stdin sys stdin buffer read readline = sys.stdin.buffer.readline readline sys.stdin.buffer.readline sys.stdin.buffer sys.stdin sys stdin buffer readline readlines = sys.stdin.buffer.readlines readlines sys.stdin.buffer.readlines sys.stdin.buffer sys.stdin sys stdin buffer readlines N, K = map(int, readline().split()) N map(int, readline().split()) map int readline().split() ().split () readline split K V = list(map(int,readline().split())) V list(map(int,readline().split())) list map(int,readline().split()) map int readline().split() ().split () readline split ans = 0 ans 0 for l in range(min(K,N)+1):
    for r in range(min(K,N)-l+1):
        res = K - (l+r)
        minus = [] 
        total = sum(V[:l])+sum(V[N-r:])
        for i in range(l):
            if V[i] < 0:
                minus.append(V[i])        
        for i in range(r):
            if V[-i-1] < 0:
                minus.append(V[-i-1])
        minus.sort()
        S = len(minus)
        rep = sum(minus[:min(S+1,res)])
        total -= rep
        # print(l,r,total,rep)
        ans = max(total,ans) l range(min(K,N)+1) range min(K,N)+1 min(K,N) min K N 1 for r in range(min(K,N)-l+1):
        res = K - (l+r)
        minus = [] 
        total = sum(V[:l])+sum(V[N-r:])
        for i in range(l):
            if V[i] < 0:
                minus.append(V[i])        
        for i in range(r):
            if V[-i-1] < 0:
                minus.append(V[-i-1])
        minus.sort()
        S = len(minus)
        rep = sum(minus[:min(S+1,res)])
        total -= rep
        # print(l,r,total,rep)
        ans = max(total,ans) r range(min(K,N)-l+1) range min(K,N)-l+1 min(K,N)-l min(K,N) min K N l 1 res = K - (l+r) res K - (l+r) K l+r l r minus = [] minus [] total = sum(V[:l])+sum(V[N-r:]) total sum(V[:l])+sum(V[N-r:]) sum(V[:l]) sum V[:l] V :l l sum(V[N-r:]) sum V[N-r:] V N-r: N-r N r for i in range(l):
            if V[i] < 0:
                minus.append(V[i])        
         i range(l) range l if V[i] < 0:
                minus.append(V[i])        
         V[i] < 0 V[i] V i 0 minus.append(V[i]) minus.append minus append V[i] V i for i in range(r):
            if V[-i-1] < 0:
                minus.append(V[-i-1])
         i range(r) range r if V[-i-1] < 0:
                minus.append(V[-i-1])
         V[-i-1] < 0 V[-i-1] V -i-1 -i i 1 0 minus.append(V[-i-1]) minus.append minus append V[-i-1] V -i-1 -i i 1 minus.sort() minus.sort minus sort S = len(minus) S len(minus) len minus rep = sum(minus[:min(S+1,res)]) rep sum(minus[:min(S+1,res)]) sum minus[:min(S+1,res)] minus :min(S+1,res) min(S+1,res) min S+1 S 1 res total -= rep total rep ans = max(total,ans) ans max(total,ans) max total ans print(ans) print ans read = sys.stdin.buffer.read sys.stdin.buffer.read read res = K - (l+r) K - (l+r) res ans = 0 0 ans ans = max(total,ans) max(total,ans) ans total = sum(V[:l])+sum(V[N-r:]) sum(V[:l])+sum(V[N-r:]) total V = list(map(int,readline().split())) list(map(int,readline().split())) V K = map(int, readline().split()) map(int, readline().split()) K S = len(minus) len(minus) S total -= rep rep total minus = [] [] minus N, K = map(int, readline().split()) map(int, readline().split()) N rep = sum(minus[:min(S+1,res)]) sum(minus[:min(S+1,res)]) rep readline = sys.stdin.buffer.readline sys.stdin.buffer.readline readline readlines = sys.stdin.buffer.readlines sys.stdin.buffer.readlines readlines
# -*- coding: utf-8 -*-
#D - equeue
import sys 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, K = map(int, readline().split())
V = list(map(int,readline().split()))

ans = 0
for l in range(min(K,N)+1):
    for r in range(min(K,N)-l+1):
        res = K - (l+r)
        minus = [] 
        total = sum(V[:l])+sum(V[N-r:])
        for i in range(l):
            if V[i] < 0:
                minus.append(V[i])        
        for i in range(r):
            if V[-i-1] < 0:
                minus.append(V[-i-1])
        minus.sort()
        S = len(minus)
        rep = sum(minus[:min(S+1,res)])
        total -= rep
        # print(l,r,total,rep)
        ans = max(total,ans)
print(ans) 