from itertools import chain

 

R = lambda: list(map(int, input().split()))

n, k = R()

v = list(R())

a = sorted((x, i) for i, x in enumerate(v) if x < 0)

r = 0

for i in range(1, min(n, k) + 1):

    for j in range(i):

        r1, r2 = list(range(i - j)), list(range(n - j, n))

        s = sum(v[m] for m in chain(r1, r2))

        j = i

        for x, m in a:

            if j == k:

                break

            if m in r1 or m in r2:

                s -= x

                j += 1

        r = max(r, s)

print(r)

from itertools import chain

 

R = lambda: list(map(int, input().split()))

n, k = R()

v = list(R())

a = sorted((x, i) for i, x in enumerate(v) if x < 0)

r = 0

for i in range(1, min(n, k) + 1):

    for j in range(i):

        r1, r2 = i - j, n - j

        s = sum(v[m] for m in chain(list(range(r1)), list(range(r2, n))))

        j = i

        for x, m in a:

            if j == k:

                break

            if m < r1 or m >= r2:

                s -= x

                j += 1

        r = max(r, s)

print(r)

from itertools import chain

R = lambda: list(map(int, input().split()))
n, k = R()
v = list(R())
a = sorted((x, i) for i, x in enumerate(v) if x < 0)
r = 0
for i in range(1, min(n, k) + 1):
    for j in range(i):
        r1, r2 = list(range(i - j)), list(range(n - j, n))
        s = sum(v[m] for m in chain(r1, r2))
        j = i
        for x, m in a:
            if j == k:
                break
            if m in r1 or m in r2:
                s -= x
                j += 1
        r = max(r, s)
print(r)

from itertools import chain

R = lambda: list(map(int, input().split()))
n, k = R()
v = list(R())
a = sorted((x, i) for i, x in enumerate(v) if x < 0)
r = 0
for i in range(1, min(n, k) + 1):
    for j in range(i):
        r1, r2 = i - j, n - j
        s = sum(v[m] for m in chain(list(range(r1)), list(range(r2, n))))
        j = i
        for x, m in a:
            if j == k:
                break
            if m < r1 or m >= r2:
                s -= x
                j += 1
        r = max(r, s)
print(r)

-        r1, r2 = list(range(i - j)), list(range(n - j, n)) -        s = sum(v[m] for m in chain(r1, r2)) +        r1, r2 = i - j, n - j +        s = sum(v[m] for m in chain(list(range(r1)), list(range(r2, n)))) -            if m in r1 or m in r2: +            if m < r1 or m >= r2: