n, k = map(int, input().split())
v = list(map(int, input().split()))
ans = 0
for i in range(min(n, k) + 1):
    for j in range(min(n, k) - i + 1):
        lis = sorted(v[:i] + v[n - j:])
        for l in range(k - i - j + 1):
            ans = max(ans, sum(lis[l:]))
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 i in range(min(n, k) + 1):
    for j in range(min(n, k) - i + 1):
        lis = sorted(v[:i] + v[n - j:])
        for l in range(k - i - j + 1):
            ans = max(ans, sum(lis[l:])) i range(min(n, k) + 1) range min(n, k) + 1 min(n, k) min n k 1 for j in range(min(n, k) - i + 1):
        lis = sorted(v[:i] + v[n - j:])
        for l in range(k - i - j + 1):
            ans = max(ans, sum(lis[l:])) j range(min(n, k) - i + 1) range min(n, k) - i + 1 min(n, k) - i min(n, k) min n k i 1 lis = sorted(v[:i] + v[n - j:]) lis sorted(v[:i] + v[n - j:]) sorted v[:i] + v[n - j:] v[:i] v :i i v[n - j:] v n - j: n - j n j for l in range(k - i - j + 1):
            ans = max(ans, sum(lis[l:])) l range(k - i - j + 1) range k - i - j + 1 k - i - j k - i k i j 1 ans = max(ans, sum(lis[l:])) ans max(ans, sum(lis[l:])) max ans sum(lis[l:]) sum lis[l:] lis l: l print(ans) print ans v = list(map(int, input().split())) list(map(int, input().split())) v ans = 0 0 ans k = map(int, input().split()) map(int, input().split()) k ans = max(ans, sum(lis[l:])) max(ans, sum(lis[l:])) ans n, k = map(int, input().split()) map(int, input().split()) n lis = sorted(v[:i] + v[n - j:]) sorted(v[:i] + v[n - j:]) lis
n, k = map(int, input().split())
v = list(map(int, input().split()))
ans = 0
for i in range(min(n, k) + 1):
    for j in range(min(n, k) - i + 1):
        lis = sorted(v[:i] + v[n - j:])
        for l in range(k - i - j + 1):
            ans = max(ans, sum(lis[l:]))
print(ans)