import sys

sys.setrecursionlimit(10 ** 9)



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

V = list(map(int, input().split()))

V2 = V * 2

answer = 0

for i in range(1, min(N, K)+1): # iは宝石を取り出す個数

    for j in range(0, min(i, K-i)+1): # jは何個の宝石を手離すか

        for k in range(max(0, N-i), N+1): # V2の中で何番目から取り出すか

            use = V2[k:k+i]

            use.sort()

            s = sum(use[j:])

            if s > answer:

                answer = s



print(answer)

# coding: utf-8

import sys

sys.setrecursionlimit(10 ** 7)



sr = lambda: sys.stdin.readline().rstrip()

ir = lambda: int(sr())

lr = lambda: list(map(int, sr().split()))



# 持っている宝石をDに詰めるのは最後

N, K = lr()

V = lr()

answer = 0

V = V[::-1] + V[::-1]

for x in range(K+1):

    # x回Dから取り出す、K-x回戻すことが可能

    x = min(x, N)

    for i in range(N-1, N-1+x+1):

        take = V[i-x+1:i+1]

        take.sort(reverse=True)

        result = sum(take)

        if result > answer:

            answer = result

        for j in range(K-x):

            if take:

                result -= take.pop()

                if result > answer:

                    answer = result



print(answer)

import sys

sys.setrecursionlimit(10**9)
N, K = list(map(int, input().split()))
V = list(map(int, input().split()))
V2 = V * 2
answer = 0
for i in range(1, min(N, K) + 1):  # iは宝石を取り出す個数
    for j in range(0, min(i, K - i) + 1):  # jは何個の宝石を手離すか
        for k in range(max(0, N - i), N + 1):  # V2の中で何番目から取り出すか
            use = V2[k : k + i]
            use.sort()
            s = sum(use[j:])
            if s > answer:
                answer = s
print(answer)

# coding: utf-8
import sys

sys.setrecursionlimit(10**7)
sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
# 持っている宝石をDに詰めるのは最後
N, K = lr()
V = lr()
answer = 0
V = V[::-1] + V[::-1]
for x in range(K + 1):
    # x回Dから取り出す、K-x回戻すことが可能
    x = min(x, N)
    for i in range(N - 1, N - 1 + x + 1):
        take = V[i - x + 1 : i + 1]
        take.sort(reverse=True)
        result = sum(take)
        if result > answer:
            answer = result
        for j in range(K - x):
            if take:
                result -= take.pop()
                if result > answer:
                    answer = result
print(answer)

+# coding: utf-8 -sys.setrecursionlimit(10**9) -N, K = list(map(int, input().split())) -V = list(map(int, input().split())) -V2 = V * 2 +sys.setrecursionlimit(10**7) +sr = lambda: sys.stdin.readline().rstrip() +ir = lambda: int(sr()) +lr = lambda: list(map(int, sr().split())) +# 持っている宝石をDに詰めるのは最後 +N, K = lr() +V = lr() -for i in range(1, min(N, K) + 1):  # iは宝石を取り出す個数 -    for j in range(0, min(i, K - i) + 1):  # jは何個の宝石を手離すか -        for k in range(max(0, N - i), N + 1):  # V2の中で何番目から取り出すか -            use = V2[k : k + i] -            use.sort() -            s = sum(use[j:]) -            if s > answer: -                answer = s +V = V[::-1] + V[::-1] +for x in range(K + 1): +    # x回Dから取り出す、K-x回戻すことが可能 +    x = min(x, N) +    for i in range(N - 1, N - 1 + x + 1): +        take = V[i - x + 1 : i + 1] +        take.sort(reverse=True) +        result = sum(take) +        if result > answer: +            answer = result +        for j in range(K - x): +            if take: +                result -= take.pop() +                if result > answer: +                    answer = result