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

c = min(n, k)
ans = 0
for a in range(c + 1):
    for b in range(c + 1 - a):
        w = v[:a] + v[n-b:]  # 手持ち
        w.sort()
        for i in range(k - (a + b)):
            if len(w) > 0 and w[0] < 0:
                del w[0]
            else:
                break
        ans = max(ans, sum(w))
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 c = min(n, k) c min(n, k) min n k ans = 0 ans 0 for a in range(c + 1):
    for b in range(c + 1 - a):
        w = v[:a] + v[n-b:]  # 手持ち
        w.sort()
        for i in range(k - (a + b)):
            if len(w) > 0 and w[0] < 0:
                del w[0]
            else:
                break
        ans = max(ans, sum(w)) a range(c + 1) range c + 1 c 1 for b in range(c + 1 - a):
        w = v[:a] + v[n-b:]  # 手持ち
        w.sort()
        for i in range(k - (a + b)):
            if len(w) > 0 and w[0] < 0:
                del w[0]
            else:
                break
        ans = max(ans, sum(w)) b range(c + 1 - a) range c + 1 - a c + 1 c 1 a w = v[:a] + v[n-b:] w v[:a] + v[n-b:] v[:a] v :a a v[n-b:] v n-b: n-b n b w.sort() w.sort w sort for i in range(k - (a + b)):
            if len(w) > 0 and w[0] < 0:
                del w[0]
            else:
                break
         i range(k - (a + b)) range k - (a + b) k a + b a b if len(w) > 0 and w[0] < 0:
                del w[0]
            else:
                break
         len(w) > 0 and w[0] < 0 len(w) > 0 len(w) len w 0 w[0] < 0 w[0] w 0 0 del w[0] w[0] w 0 break ans = max(ans, sum(w)) ans max(ans, sum(w)) max ans sum(w) sum w print(ans) print ans v = list(map(int, input().split())) list(map(int, input().split())) v c = min(n, k) min(n, k) c ans = 0 0 ans w = v[:a] + v[n-b:] v[:a] + v[n-b:] w ans = max(ans, sum(w)) max(ans, sum(w)) ans k = map(int, input().split()) map(int, input().split()) k n, k = map(int, input().split()) map(int, input().split()) n
n, k = map(int, input().split())
v = list(map(int, input().split()))  # 筒

c = min(n, k)
ans = 0
for a in range(c + 1):
    for b in range(c + 1 - a):
        w = v[:a] + v[n-b:]  # 手持ち
        w.sort()
        for i in range(k - (a + b)):
            if len(w) > 0 and w[0] < 0:
                del w[0]
            else:
                break
        ans = max(ans, sum(w))
print(ans)