N,K = map(int,input().split())
V = list(map(int,input().split()))

ans = 0
for l in range(N):
    if l > K: break
    for r in range(N-l+1):
        if l+r > K: break
        vs = V[:l] + (V[-r:] if r>0 else [])
        vs.sort()
        k = K-l-r
        t = 0
        for v in vs:
            if v < 0 and k > 0:
                k -= 1
                continue
            t += v
        ans = max(ans,t)
print(ans) 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 ans = 0 ans 0 for l in range(N):
    if l > K: break
    for r in range(N-l+1):
        if l+r > K: break
        vs = V[:l] + (V[-r:] if r>0 else [])
        vs.sort()
        k = K-l-r
        t = 0
        for v in vs:
            if v < 0 and k > 0:
                k -= 1
                continue
            t += v
        ans = max(ans,t) l range(N) range N if l > K: break
     l > K l K for r in range(N-l+1):
        if l+r > K: break
        vs = V[:l] + (V[-r:] if r>0 else [])
        vs.sort()
        k = K-l-r
        t = 0
        for v in vs:
            if v < 0 and k > 0:
                k -= 1
                continue
            t += v
        ans = max(ans,t) r range(N-l+1) range N-l+1 N-l N l 1 if l+r > K: break
         l+r > K l+r l r K vs = V[:l] + (V[-r:] if r>0 else []) vs V[:l] + (V[-r:] if r>0 else []) V[:l] V :l l V[-r:] if r>0 else [] r>0 r 0 V[-r:] V -r: -r r [] vs.sort() vs.sort vs sort k = K-l-r k K-l-r K-l K l r t = 0 t 0 for v in vs:
            if v < 0 and k > 0:
                k -= 1
                continue
            t += v
         v vs if v < 0 and k > 0:
                k -= 1
                continue
             v < 0 and k > 0 v < 0 v 0 k > 0 k 0 k -= 1 k 1 continue t += v t v ans = max(ans,t) ans max(ans,t) max ans t print(ans) print ans ans = 0 0 ans ans = max(ans,t) max(ans,t) ans k -= 1 1 k K = map(int,input().split()) map(int,input().split()) K k = K-l-r K-l-r k V = list(map(int,input().split())) list(map(int,input().split())) V t = 0 0 t t += v v t N,K = map(int,input().split()) map(int,input().split()) N vs = V[:l] + (V[-r:] if r>0 else []) V[:l] + (V[-r:] if r>0 else []) vs
N,K = map(int,input().split())
V = list(map(int,input().split()))

ans = 0
for l in range(N):
    if l > K: break
    for r in range(N-l+1):
        if l+r > K: break
        vs = V[:l] + (V[-r:] if r>0 else [])
        vs.sort()
        k = K-l-r
        t = 0
        for v in vs:
            if v < 0 and k > 0:
                k -= 1
                continue
            t += v
        ans = max(ans,t)
print(ans)