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

ans = -10**9
for back in range(n+1):
    for left in range(min(k-back+1, n+1)):
        for right in range(min(k-back-left+1, n-left+1)):
            hand = []
            hand.extend(v[:left])
            if right>0:
                hand.extend(v[-right:])
            hand.sort()
            ans = max(ans, sum(hand[back:]))

print(ans) n,k = list(map(int, input().split())) n list(map(int, input().split())) list 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 = -10**9 ans -10**9 -10 9 for back in range(n+1):
    for left in range(min(k-back+1, n+1)):
        for right in range(min(k-back-left+1, n-left+1)):
            hand = []
            hand.extend(v[:left])
            if right>0:
                hand.extend(v[-right:])
            hand.sort()
            ans = max(ans, sum(hand[back:])) back range(n+1) range n+1 n 1 for left in range(min(k-back+1, n+1)):
        for right in range(min(k-back-left+1, n-left+1)):
            hand = []
            hand.extend(v[:left])
            if right>0:
                hand.extend(v[-right:])
            hand.sort()
            ans = max(ans, sum(hand[back:])) left range(min(k-back+1, n+1)) range min(k-back+1, n+1) min k-back+1 k-back k back 1 n+1 n 1 for right in range(min(k-back-left+1, n-left+1)):
            hand = []
            hand.extend(v[:left])
            if right>0:
                hand.extend(v[-right:])
            hand.sort()
            ans = max(ans, sum(hand[back:])) right range(min(k-back-left+1, n-left+1)) range min(k-back-left+1, n-left+1) min k-back-left+1 k-back-left k-back k back left 1 n-left+1 n-left n left 1 hand = [] hand [] hand.extend(v[:left]) hand.extend hand extend v[:left] v :left left if right>0:
                hand.extend(v[-right:])
             right>0 right 0 hand.extend(v[-right:]) hand.extend hand extend v[-right:] v -right: -right right hand.sort() hand.sort hand sort ans = max(ans, sum(hand[back:])) ans max(ans, sum(hand[back:])) max ans sum(hand[back:]) sum hand[back:] hand back: back print(ans) print ans ans = max(ans, sum(hand[back:])) max(ans, sum(hand[back:])) ans ans = -10**9 -10**9 ans n,k = list(map(int, input().split())) list(map(int, input().split())) n k = list(map(int, input().split())) list(map(int, input().split())) k hand = [] [] hand v = list(map(int, input().split())) list(map(int, input().split())) v
n,k = list(map(int, input().split()))
v = list(map(int, input().split()))

ans = -10**9
for back in range(n+1):
    for left in range(min(k-back+1, n+1)):
        for right in range(min(k-back-left+1, n-left+1)):
            hand = []
            hand.extend(v[:left])
            if right>0:
                hand.extend(v[-right:])
            hand.sort()
            ans = max(ans, sum(hand[back:]))

print(ans)