from collections import deque
n, k = map(int, input().split())
v = list(map(int, input().split()))
ans = 0
for i in range(1, min(n, k+1)):
    vv = deque(v)
    q = deque(v[:i])
    for _ in range(i+1):
        tmp = list(q)
        tmp.sort()
        rem = k-i
        s = sum(tmp)
        for j in tmp:
            if rem==0 or j>=0:
                break
            s -= j
            rem -= 1
        ans = max(ans, s)
        q.pop()
        q.appendleft(vv.pop())
if k>=n:
    v.sort()
    rem = k-n
    s = sum(v)
    for j in v:
        if rem==0 or j>=0:
            break
        s -= j
        rem -= 1
    ans = max(ans, s)
print(ans) from collections import deque 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 i in range(1, min(n, k+1)):
    vv = deque(v)
    q = deque(v[:i])
    for _ in range(i+1):
        tmp = list(q)
        tmp.sort()
        rem = k-i
        s = sum(tmp)
        for j in tmp:
            if rem==0 or j>=0:
                break
            s -= j
            rem -= 1
        ans = max(ans, s)
        q.pop()
        q.appendleft(vv.pop()) i range(1, min(n, k+1)) range 1 min(n, k+1) min n k+1 k 1 vv = deque(v) vv deque(v) deque v q = deque(v[:i]) q deque(v[:i]) deque v[:i] v :i i for _ in range(i+1):
        tmp = list(q)
        tmp.sort()
        rem = k-i
        s = sum(tmp)
        for j in tmp:
            if rem==0 or j>=0:
                break
            s -= j
            rem -= 1
        ans = max(ans, s)
        q.pop()
        q.appendleft(vv.pop()) _ range(i+1) range i+1 i 1 tmp = list(q) tmp list(q) list q tmp.sort() tmp.sort tmp sort rem = k-i rem k-i k i s = sum(tmp) s sum(tmp) sum tmp for j in tmp:
            if rem==0 or j>=0:
                break
            s -= j
            rem -= 1
         j tmp if rem==0 or j>=0:
                break
             rem==0 or j>=0 rem==0 rem 0 j>=0 j 0 break s -= j s j rem -= 1 rem 1 ans = max(ans, s) ans max(ans, s) max ans s q.pop() q.pop q pop q.appendleft(vv.pop()) q.appendleft q appendleft vv.pop() vv.pop vv pop if k>=n:
    v.sort()
    rem = k-n
    s = sum(v)
    for j in v:
        if rem==0 or j>=0:
            break
        s -= j
        rem -= 1
    ans = max(ans, s) k>=n k n v.sort() v.sort v sort rem = k-n rem k-n k n s = sum(v) s sum(v) sum v for j in v:
        if rem==0 or j>=0:
            break
        s -= j
        rem -= 1
     j v if rem==0 or j>=0:
            break
         rem==0 or j>=0 rem==0 rem 0 j>=0 j 0 break s -= j s j rem -= 1 rem 1 ans = max(ans, s) ans max(ans, s) max ans s print(ans) print ans v = list(map(int, input().split())) list(map(int, input().split())) v rem = k-i k-i rem s -= j j s s = sum(tmp) sum(tmp) s ans = 0 0 ans rem -= 1 1 rem tmp = list(q) list(q) tmp s = sum(v) sum(v) s rem = k-n k-n rem vv = deque(v) deque(v) vv ans = max(ans, s) max(ans, s) ans k = map(int, input().split()) map(int, input().split()) k ans = max(ans, s) max(ans, s) ans q = deque(v[:i]) deque(v[:i]) q rem -= 1 1 rem n, k = map(int, input().split()) map(int, input().split()) n s -= j j s
from collections import deque
n, k = map(int, input().split())
v = list(map(int, input().split()))
ans = 0
for i in range(1, min(n, k+1)):
    vv = deque(v)
    q = deque(v[:i])
    for _ in range(i+1):
        tmp = list(q)
        tmp.sort()
        rem = k-i
        s = sum(tmp)
        for j in tmp:
            if rem==0 or j>=0:
                break
            s -= j
            rem -= 1
        ans = max(ans, s)
        q.pop()
        q.appendleft(vv.pop())
if k>=n:
    v.sort()
    rem = k-n
    s = sum(v)
    for j in v:
        if rem==0 or j>=0:
            break
        s -= j
        rem -= 1
    ans = max(ans, s)
print(ans)