#python3

from collections import deque

from heapq import heappop, heappush

def main():

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

    vs = [int(i) for i in input().split()]

    ans = 0

    for l in range(k+1):

        for r in range(k-l+1):

            dl = k-l-r

            q = deque(vs)

            hav = []

            for _ in range(l):

                if len(q) == 0:

                    continue

                v = q.popleft()

                heappush(hav, v)

            for _ in range(r):

                if len(q) == 0:

                    continue

                u = q.pop()

                heappush(hav, u)

            for i in range(dl):

                if len(hav) == 0:

                    break

                val = heappop(hav)

                if val > 0:

                    heappush(hav, val)

            ans = max(ans, sum(hav))

    print(ans)

main()
import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

from heapq import heapify, heappop, heappush 

def main():

    N, K = list(map(int, readline().split()))

    V = [int(i) for i in readline().split()]

    A = V[::-1]

    ans = 0

    for l in range(K+1):

        for r in range(K+1-l):

            if l+r>N:

                continue

            rest = K-(l+r)

            hp = V[:l] + A[:r]

            heapify(hp)

            for _ in range(rest):

                if len(hp)==0:

                    break

                v = heappop(hp)

                if v > 0:

                    heappush(hp, v)

            ans = max(ans, sum(hp))

    print(ans)

if __name__ == '__main__':

    main()

# python3
from collections import deque
from heapq import heappop, heappush


def main():
    n, k = list(map(int, input().split()))
    vs = [int(i) for i in input().split()]
    ans = 0
    for l in range(k + 1):
        for r in range(k - l + 1):
            dl = k - l - r
            q = deque(vs)
            hav = []
            for _ in range(l):
                if len(q) == 0:
                    continue
                v = q.popleft()
                heappush(hav, v)
            for _ in range(r):
                if len(q) == 0:
                    continue
                u = q.pop()
                heappush(hav, u)
            for i in range(dl):
                if len(hav) == 0:
                    break
                val = heappop(hav)
                if val > 0:
                    heappush(hav, val)
            ans = max(ans, sum(hav))
    print(ans)


main()

import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from heapq import heapify, heappop, heappush


def main():
    N, K = list(map(int, readline().split()))
    V = [int(i) for i in readline().split()]
    A = V[::-1]
    ans = 0
    for l in range(K + 1):
        for r in range(K + 1 - l):
            if l + r > N:
                continue
            rest = K - (l + r)
            hp = V[:l] + A[:r]
            heapify(hp)
            for _ in range(rest):
                if len(hp) == 0:
                    break
                v = heappop(hp)
                if v > 0:
                    heappush(hp, v)
            ans = max(ans, sum(hp))
    print(ans)


if __name__ == "__main__":
    main()

-# python3 -from collections import deque -from heapq import heappop, heappush +import sys + +read = sys.stdin.buffer.read +readline = sys.stdin.buffer.readline +readlines = sys.stdin.buffer.readlines +from heapq import heapify, heappop, heappush -    n, k = list(map(int, input().split())) -    vs = [int(i) for i in input().split()] +    N, K = list(map(int, readline().split())) +    V = [int(i) for i in readline().split()] +    A = V[::-1] -    for l in range(k + 1): -        for r in range(k - l + 1): -            dl = k - l - r -            q = deque(vs) -            hav = [] -            for _ in range(l): -                if len(q) == 0: -                    continue -                v = q.popleft() -                heappush(hav, v) -            for _ in range(r): -                if len(q) == 0: -                    continue -                u = q.pop() -                heappush(hav, u) -            for i in range(dl): -                if len(hav) == 0: +    for l in range(K + 1): +        for r in range(K + 1 - l): +            if l + r > N: +                continue +            rest = K - (l + r) +            hp = V[:l] + A[:r] +            heapify(hp) +            for _ in range(rest): +                if len(hp) == 0: -                val = heappop(hav) -                if val > 0: -                    heappush(hav, val) -            ans = max(ans, sum(hav)) +                v = heappop(hp) +                if v > 0: +                    heappush(hp, v) +            ans = max(ans, sum(hp)) -main() +if __name__ == "__main__": +    main()