# D
n, k = map(int, input().split())
v = list(map(int, input().split()))
q = []
ans = 0
for a in range(min(n, k) + 1):
    for b in range(min(n, k) - a + 1):
        # print(a, b)
        if a == 0:
            pass
        else:
            q.extend(v[:a])
        if b == 0:
            pass
        else:
            q.extend(v[-b:])
        q.sort()
        pick = k - (a + b)
        for i in range(min(pick, len(q))):
            # print(i, q)
            if q[0] < 0:
                q.reverse()
                q.pop()
                q.reverse()
            else:
                break
        s = sum(q)
        # print(q, pick, q[:pick], s)
        if ans < s:
            ans = s
        q.clear()
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 q = [] q [] ans = 0 ans 0 for a in range(min(n, k) + 1):
    for b in range(min(n, k) - a + 1):
        # print(a, b)
        if a == 0:
            pass
        else:
            q.extend(v[:a])
        if b == 0:
            pass
        else:
            q.extend(v[-b:])
        q.sort()
        pick = k - (a + b)
        for i in range(min(pick, len(q))):
            # print(i, q)
            if q[0] < 0:
                q.reverse()
                q.pop()
                q.reverse()
            else:
                break
        s = sum(q)
        # print(q, pick, q[:pick], s)
        if ans < s:
            ans = s
        q.clear() a range(min(n, k) + 1) range min(n, k) + 1 min(n, k) min n k 1 for b in range(min(n, k) - a + 1):
        # print(a, b)
        if a == 0:
            pass
        else:
            q.extend(v[:a])
        if b == 0:
            pass
        else:
            q.extend(v[-b:])
        q.sort()
        pick = k - (a + b)
        for i in range(min(pick, len(q))):
            # print(i, q)
            if q[0] < 0:
                q.reverse()
                q.pop()
                q.reverse()
            else:
                break
        s = sum(q)
        # print(q, pick, q[:pick], s)
        if ans < s:
            ans = s
        q.clear() b range(min(n, k) - a + 1) range min(n, k) - a + 1 min(n, k) - a min(n, k) min n k a 1 if a == 0:
            pass
        else:
            q.extend(v[:a])
         a == 0 a 0 q.extend(v[:a]) q.extend q extend v[:a] v :a a if b == 0:
            pass
        else:
            q.extend(v[-b:])
         b == 0 b 0 q.extend(v[-b:]) q.extend q extend v[-b:] v -b: -b b q.sort() q.sort q sort pick = k - (a + b) pick k - (a + b) k a + b a b for i in range(min(pick, len(q))):
            # print(i, q)
            if q[0] < 0:
                q.reverse()
                q.pop()
                q.reverse()
            else:
                break
         i range(min(pick, len(q))) range min(pick, len(q)) min pick len(q) len q if q[0] < 0:
                q.reverse()
                q.pop()
                q.reverse()
            else:
                break
         q[0] < 0 q[0] q 0 0 q.reverse() q.reverse q reverse q.pop() q.pop q pop q.reverse() q.reverse q reverse break s = sum(q) s sum(q) sum q if ans < s:
            ans = s
         ans < s ans s ans = s ans s q.clear() q.clear q clear print(ans) print ans ans = s s ans ans = 0 0 ans n, k = map(int, input().split()) map(int, input().split()) n s = sum(q) sum(q) s k = map(int, input().split()) map(int, input().split()) k q = [] [] q pick = k - (a + b) k - (a + b) pick v = list(map(int, input().split())) list(map(int, input().split())) v
# D
n, k = map(int, input().split())
v = list(map(int, input().split()))
q = []
ans = 0
for a in range(min(n, k) + 1):
    for b in range(min(n, k) - a + 1):
        # print(a, b)
        if a == 0:
            pass
        else:
            q.extend(v[:a])
        if b == 0:
            pass
        else:
            q.extend(v[-b:])
        q.sort()
        pick = k - (a + b)
        for i in range(min(pick, len(q))):
            # print(i, q)
            if q[0] < 0:
                q.reverse()
                q.pop()
                q.reverse()
            else:
                break
        s = sum(q)
        # print(q, pick, q[:pick], s)
        if ans < s:
            ans = s
        q.clear()
print(ans)
