import sys,queue,math,copy,itertools,bisect,collections
INF = 10**9
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
_LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
N,K = LI()
dq = LI()

ans = -INF
for r in range(N+1):
    if K < N - r: continue

    ret = 0
    for i in range(N-r+1):
        q = dq[:i] + dq[i+r:]
        ret = sum(q)
        q.sort()
        for j in range(K - (N-r)):
            if j >= len(q)-1 : break
            if q[j] < 0:
                ret -= q[j]
            else:
                break
        ans = max(ans,ret)
print(ans) import sys,queue,math,copy,itertools,bisect,collections sys queue math copy itertools bisect collections INF = 10**9 INF 10**9 10 9 int(x) for x in sys.stdin.readline().split() for x in sys.stdin.readline().split() x sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split for x in sys.stdin.readline().split() int(x) int x LI = lambda : [int(x) for x in sys.stdin.readline().split()] LI lambda : [int(x) for x in sys.stdin.readline().split()] [int(x) for x in sys.stdin.readline().split()] int(x)-1 for x in sys.stdin.readline().split() for x in sys.stdin.readline().split() x sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split for x in sys.stdin.readline().split() int(x)-1 int(x) int x 1 _LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()] _LI lambda : [int(x)-1 for x in sys.stdin.readline().split()] [int(x)-1 for x in sys.stdin.readline().split()] NI = lambda : int(sys.stdin.readline()) NI lambda : int(sys.stdin.readline()) int(sys.stdin.readline()) int sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline N,K = LI() N LI() LI K dq = LI() dq LI() LI ans = -INF ans -INF INF for r in range(N+1):
    if K < N - r: continue

    ret = 0
    for i in range(N-r+1):
        q = dq[:i] + dq[i+r:]
        ret = sum(q)
        q.sort()
        for j in range(K - (N-r)):
            if j >= len(q)-1 : break
            if q[j] < 0:
                ret -= q[j]
            else:
                break
        ans = max(ans,ret) r range(N+1) range N+1 N 1 if K < N - r: continue

     K < N - r K N - r N r ret = 0 ret 0 for i in range(N-r+1):
        q = dq[:i] + dq[i+r:]
        ret = sum(q)
        q.sort()
        for j in range(K - (N-r)):
            if j >= len(q)-1 : break
            if q[j] < 0:
                ret -= q[j]
            else:
                break
        ans = max(ans,ret) i range(N-r+1) range N-r+1 N-r N r 1 q = dq[:i] + dq[i+r:] q dq[:i] + dq[i+r:] dq[:i] dq :i i dq[i+r:] dq i+r: i+r i r ret = sum(q) ret sum(q) sum q q.sort() q.sort q sort for j in range(K - (N-r)):
            if j >= len(q)-1 : break
            if q[j] < 0:
                ret -= q[j]
            else:
                break
         j range(K - (N-r)) range K - (N-r) K N-r N r if j >= len(q)-1 : break
             j >= len(q)-1 j len(q)-1 len(q) len q 1 if q[j] < 0:
                ret -= q[j]
            else:
                break
         q[j] < 0 q[j] q j 0 ret -= q[j] ret q[j] q j break ans = max(ans,ret) ans max(ans,ret) max ans ret print(ans) print ans K = LI() LI() K dq = LI() LI() dq ret = sum(q) sum(q) ret ans = max(ans,ret) max(ans,ret) ans ans = -INF -INF ans ret -= q[j] q[j] ret ret = 0 0 ret NI = lambda : int(sys.stdin.readline()) lambda : int(sys.stdin.readline()) NI q = dq[:i] + dq[i+r:] dq[:i] + dq[i+r:] q INF = 10**9 10**9 INF LI = lambda : [int(x) for x in sys.stdin.readline().split()] lambda : [int(x) for x in sys.stdin.readline().split()] LI N,K = LI() LI() N _LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()] lambda : [int(x)-1 for x in sys.stdin.readline().split()] _LI
import sys,queue,math,copy,itertools,bisect,collections
INF = 10**9
LI = lambda : [int(x) for x in sys.stdin.readline().split()]
_LI = lambda : [int(x)-1 for x in sys.stdin.readline().split()]
NI = lambda : int(sys.stdin.readline())
N,K = LI()
dq = LI()

ans = -INF
for r in range(N+1):
    if K < N - r: continue

    ret = 0
    for i in range(N-r+1):
        q = dq[:i] + dq[i+r:]
        ret = sum(q)
        q.sort()
        for j in range(K - (N-r)):
            if j >= len(q)-1 : break
            if q[j] < 0:
                ret -= q[j]
            else:
                break
        ans = max(ans,ret)
print(ans)
