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

ans = 0
for left in range(n + 1):
    for right in range(n + 1):
        if left == 0 and right == 0:
            continue
        rest = k - left - right
        if left + right > n or rest < 0:
            break
        arr = v[:left] + v[n - right:]
        minus = 0
        neg = [x for x in arr if x < 0]
        if len(neg) > 0:
            neg.sort()
            minus = sum(neg[:rest])
        ans = max(ans, sum(arr) - minus)

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 left in range(n + 1):
    for right in range(n + 1):
        if left == 0 and right == 0:
            continue
        rest = k - left - right
        if left + right > n or rest < 0:
            break
        arr = v[:left] + v[n - right:]
        minus = 0
        neg = [x for x in arr if x < 0]
        if len(neg) > 0:
            neg.sort()
            minus = sum(neg[:rest])
        ans = max(ans, sum(arr) - minus) left range(n + 1) range n + 1 n 1 for right in range(n + 1):
        if left == 0 and right == 0:
            continue
        rest = k - left - right
        if left + right > n or rest < 0:
            break
        arr = v[:left] + v[n - right:]
        minus = 0
        neg = [x for x in arr if x < 0]
        if len(neg) > 0:
            neg.sort()
            minus = sum(neg[:rest])
        ans = max(ans, sum(arr) - minus) right range(n + 1) range n + 1 n 1 if left == 0 and right == 0:
            continue
         left == 0 and right == 0 left == 0 left 0 right == 0 right 0 continue rest = k - left - right rest k - left - right k - left k left right if left + right > n or rest < 0:
            break
         left + right > n or rest < 0 left + right > n left + right left right n rest < 0 rest 0 break arr = v[:left] + v[n - right:] arr v[:left] + v[n - right:] v[:left] v :left left v[n - right:] v n - right: n - right n right minus = 0 minus 0 x for x in arr if x < 0 for x in arr if x < 0 x arr x < 0 x 0 if x < 0 x neg = [x for x in arr if x < 0] neg [x for x in arr if x < 0] if len(neg) > 0:
            neg.sort()
            minus = sum(neg[:rest])
         len(neg) > 0 len(neg) len neg 0 neg.sort() neg.sort neg sort minus = sum(neg[:rest]) minus sum(neg[:rest]) sum neg[:rest] neg :rest rest ans = max(ans, sum(arr) - minus) ans max(ans, sum(arr) - minus) max ans sum(arr) - minus sum(arr) sum arr minus print(ans) print ans k = map(int, input().split()) map(int, input().split()) k minus = sum(neg[:rest]) sum(neg[:rest]) minus rest = k - left - right k - left - right rest arr = v[:left] + v[n - right:] v[:left] + v[n - right:] arr neg = [x for x in arr if x < 0] [x for x in arr if x < 0] neg ans = max(ans, sum(arr) - minus) max(ans, sum(arr) - minus) ans n, k = map(int, input().split()) map(int, input().split()) n v = list(map(int, input().split())) list(map(int, input().split())) v ans = 0 0 ans minus = 0 0 minus
n, k = map(int, input().split())
v = list(map(int, input().split()))

ans = 0
for left in range(n + 1):
    for right in range(n + 1):
        if left == 0 and right == 0:
            continue
        rest = k - left - right
        if left + right > n or rest < 0:
            break
        arr = v[:left] + v[n - right:]
        minus = 0
        neg = [x for x in arr if x < 0]
        if len(neg) > 0:
            neg.sort()
            minus = sum(neg[:rest])
        ans = max(ans, sum(arr) - minus)

print(ans)