from collections import deque

n, k = map(int, input().split())
v = list(map(int, input().split()))

w = deque(v)
ans = 0
for i in range(k+1):
    if i > n:
        break
    s = v[:i]
    for j in range(k+1-i):
        if j > n-i:
            break
        t = sorted(v[n-j:] + s, reverse=True)
        u = sum(t)
        for l in range(k+1-i-j):
            ans = max(ans, u)
            if not t:
                break
            u -= t.pop()
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 w = deque(v) w deque(v) deque v ans = 0 ans 0 for i in range(k+1):
    if i > n:
        break
    s = v[:i]
    for j in range(k+1-i):
        if j > n-i:
            break
        t = sorted(v[n-j:] + s, reverse=True)
        u = sum(t)
        for l in range(k+1-i-j):
            ans = max(ans, u)
            if not t:
                break
            u -= t.pop() i range(k+1) range k+1 k 1 if i > n:
        break
     i > n i n break s = v[:i] s v[:i] v :i i for j in range(k+1-i):
        if j > n-i:
            break
        t = sorted(v[n-j:] + s, reverse=True)
        u = sum(t)
        for l in range(k+1-i-j):
            ans = max(ans, u)
            if not t:
                break
            u -= t.pop() j range(k+1-i) range k+1-i k+1 k 1 i if j > n-i:
            break
         j > n-i j n-i n i break t = sorted(v[n-j:] + s, reverse=True) t sorted(v[n-j:] + s, reverse=True) sorted v[n-j:] + s v[n-j:] v n-j: n-j n j s reverse=True reverse True u = sum(t) u sum(t) sum t for l in range(k+1-i-j):
            ans = max(ans, u)
            if not t:
                break
            u -= t.pop() l range(k+1-i-j) range k+1-i-j k+1-i k+1 k 1 i j ans = max(ans, u) ans max(ans, u) max ans u if not t:
                break
             not t t break u -= t.pop() u t.pop() t.pop t pop print(ans) print ans ans = 0 0 ans w = deque(v) deque(v) w k = map(int, input().split()) map(int, input().split()) k u -= t.pop() t.pop() u t = sorted(v[n-j:] + s, reverse=True) sorted(v[n-j:] + s, reverse=True) t u = sum(t) sum(t) u s = v[:i] v[:i] s n, k = map(int, input().split()) map(int, input().split()) n ans = max(ans, u) max(ans, u) ans v = list(map(int, input().split())) list(map(int, input().split())) v
from collections import deque

n, k = map(int, input().split())
v = list(map(int, input().split()))

w = deque(v)
ans = 0
for i in range(k+1):
    if i > n:
        break
    s = v[:i]
    for j in range(k+1-i):
        if j > n-i:
            break
        t = sorted(v[n-j:] + s, reverse=True)
        u = sum(t)
        for l in range(k+1-i-j):
            ans = max(ans, u)
            if not t:
                break
            u -= t.pop()
print(ans)