def solve():

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

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

    V *= 2

    ans = 0

    for i in range(N+1):

        for j in range(N-1,2*N):

            num = j-i+1

            if num>K or num>N or num == 0:

                continue

            lis = V[i:j+1]

            lis.sort()

            margin = K-num

            m = sum(lis)

            k = 0

            while k < margin and k < num and lis[k]<0 :

                m -= lis[k]

                k += 1

            ans = max(ans,m)

    return ans

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

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



def solve(N,K,V):

    ans = 0

    V = V*2

    for l in range(N+1):

        for r in range(N-1,2*N):

            n = r-l+1

            if n == 0 or n>K or n>N:

                continue

            p = K-n

            W = V[l:r+1]

            W.sort()

            total = sum(W)

            firstp = W[:p]

            for w in firstp:

                if w<0:

                    total -= w

                else:

                    break

            ans = max(ans,total)

    return ans

print((solve(N,K,V)))
def solve():
    N, K = list(map(int, input().split()))
    V = list(map(int, input().split()))
    V *= 2
    ans = 0
    for i in range(N + 1):
        for j in range(N - 1, 2 * N):
            num = j - i + 1
            if num > K or num > N or num == 0:
                continue
            lis = V[i : j + 1]
            lis.sort()
            margin = K - num
            m = sum(lis)
            k = 0
            while k < margin and k < num and lis[k] < 0:
                m -= lis[k]
                k += 1
            ans = max(ans, m)
    return ans


print((solve()))

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


def solve(N, K, V):
    ans = 0
    V = V * 2
    for l in range(N + 1):
        for r in range(N - 1, 2 * N):
            n = r - l + 1
            if n == 0 or n > K or n > N:
                continue
            p = K - n
            W = V[l : r + 1]
            W.sort()
            total = sum(W)
            firstp = W[:p]
            for w in firstp:
                if w < 0:
                    total -= w
                else:
                    break
            ans = max(ans, total)
    return ans


print((solve(N, K, V)))

-def solve(): -    N, K = list(map(int, input().split())) -    V = list(map(int, input().split())) -    V *= 2 +N, K = list(map(int, input().split())) +V = list(map(int, input().split())) + + +def solve(N, K, V): -    for i in range(N + 1): -        for j in range(N - 1, 2 * N): -            num = j - i + 1 -            if num > K or num > N or num == 0: +    V = V * 2 +    for l in range(N + 1): +        for r in range(N - 1, 2 * N): +            n = r - l + 1 +            if n == 0 or n > K or n > N: -            lis = V[i : j + 1] -            lis.sort() -            margin = K - num -            m = sum(lis) -            k = 0 -            while k < margin and k < num and lis[k] < 0: -                m -= lis[k] -                k += 1 -            ans = max(ans, m) +            p = K - n +            W = V[l : r + 1] +            W.sort() +            total = sum(W) +            firstp = W[:p] +            for w in firstp: +                if w < 0: +                    total -= w +                else: +                    break +            ans = max(ans, total) -print((solve())) +print((solve(N, K, V)))