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

res = 0
r = min(n, k)
for i in range(r+1):
    for j in range(r-i+1):
        in_hand = v[:i] + v[n-j:] if i + j < n else v[:]
        in_hand.sort(reverse=True)
        for _ in range(k-len(in_hand)):
            if not in_hand or in_hand[-1] >= 0:
                break
            in_hand.pop()
        res = max(res, sum(in_hand))
print(res) 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 res = 0 res 0 r = min(n, k) r min(n, k) min n k for i in range(r+1):
    for j in range(r-i+1):
        in_hand = v[:i] + v[n-j:] if i + j < n else v[:]
        in_hand.sort(reverse=True)
        for _ in range(k-len(in_hand)):
            if not in_hand or in_hand[-1] >= 0:
                break
            in_hand.pop()
        res = max(res, sum(in_hand)) i range(r+1) range r+1 r 1 for j in range(r-i+1):
        in_hand = v[:i] + v[n-j:] if i + j < n else v[:]
        in_hand.sort(reverse=True)
        for _ in range(k-len(in_hand)):
            if not in_hand or in_hand[-1] >= 0:
                break
            in_hand.pop()
        res = max(res, sum(in_hand)) j range(r-i+1) range r-i+1 r-i r i 1 in_hand = v[:i] + v[n-j:] if i + j < n else v[:] in_hand v[:i] + v[n-j:] if i + j < n else v[:] i + j < n i + j i j n v[:i] + v[n-j:] v[:i] v :i i v[n-j:] v n-j: n-j n j v[:] v : in_hand.sort(reverse=True) in_hand.sort in_hand sort reverse=True reverse True for _ in range(k-len(in_hand)):
            if not in_hand or in_hand[-1] >= 0:
                break
            in_hand.pop()
         _ range(k-len(in_hand)) range k-len(in_hand) k len(in_hand) len in_hand if not in_hand or in_hand[-1] >= 0:
                break
             not in_hand or in_hand[-1] >= 0 not in_hand in_hand in_hand[-1] >= 0 in_hand[-1] in_hand -1 0 break in_hand.pop() in_hand.pop in_hand pop res = max(res, sum(in_hand)) res max(res, sum(in_hand)) max res sum(in_hand) sum in_hand print(res) print res k = map(int, input().split()) map(int, input().split()) k res = max(res, sum(in_hand)) max(res, sum(in_hand)) res r = min(n, k) min(n, k) r v = list(map(int, input().split())) list(map(int, input().split())) v n, k = map(int, input().split()) map(int, input().split()) n in_hand = v[:i] + v[n-j:] if i + j < n else v[:] v[:i] + v[n-j:] if i + j < n else v[:] in_hand res = 0 0 res
n, k = map(int, input().split())
v = list(map(int, input().split()))

res = 0
r = min(n, k)
for i in range(r+1):
    for j in range(r-i+1):
        in_hand = v[:i] + v[n-j:] if i + j < n else v[:]
        in_hand.sort(reverse=True)
        for _ in range(k-len(in_hand)):
            if not in_hand or in_hand[-1] >= 0:
                break
            in_hand.pop()
        res = max(res, sum(in_hand))
print(res)
