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

ans = V[0]
for l in range(min(K, N)+1):
    for r in range(min(K, N)-l+1):
        v = V[:l] + V[N-r:]
        rest = K - (l + r)
        v.sort()
        tmp = 0
        for x in v:
            if rest and x < 0:
                rest -= 1
            else:
                tmp += x
        if ans < tmp:
            ans = tmp
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 = V[0] ans V[0] V 0 for l in range(min(K, N)+1):
    for r in range(min(K, N)-l+1):
        v = V[:l] + V[N-r:]
        rest = K - (l + r)
        v.sort()
        tmp = 0
        for x in v:
            if rest and x < 0:
                rest -= 1
            else:
                tmp += x
        if ans < tmp:
            ans = tmp 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):
        v = V[:l] + V[N-r:]
        rest = K - (l + r)
        v.sort()
        tmp = 0
        for x in v:
            if rest and x < 0:
                rest -= 1
            else:
                tmp += x
        if ans < tmp:
            ans = tmp 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 v = V[:l] + V[N-r:] v V[:l] + V[N-r:] V[:l] V :l l V[N-r:] V N-r: N-r N r rest = K - (l + r) rest K - (l + r) K l + r l r v.sort() v.sort v sort tmp = 0 tmp 0 for x in v:
            if rest and x < 0:
                rest -= 1
            else:
                tmp += x
         x v if rest and x < 0:
                rest -= 1
            else:
                tmp += x
         rest and x < 0 rest x < 0 x 0 rest -= 1 rest 1 tmp += x tmp x if ans < tmp:
            ans = tmp ans < tmp ans tmp ans = tmp ans tmp print(ans) print ans N, K = map(int, input().split()) map(int, input().split()) N rest -= 1 1 rest ans = tmp tmp ans tmp += x x tmp v = V[:l] + V[N-r:] V[:l] + V[N-r:] v rest = K - (l + r) K - (l + r) rest ans = V[0] V[0] ans tmp = 0 0 tmp V = list(map(int, input().split())) list(map(int, input().split())) V K = map(int, input().split()) map(int, input().split()) K
N, K = map(int, input().split())
V = list(map(int, input().split()))

ans = V[0]
for l in range(min(K, N)+1):
    for r in range(min(K, N)-l+1):
        v = V[:l] + V[N-r:]
        rest = K - (l + r)
        v.sort()
        tmp = 0
        for x in v:
            if rest and x < 0:
                rest -= 1
            else:
                tmp += x
        if ans < tmp:
            ans = tmp
print(ans)