from heapq import*

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

*v,=list(map(int,input().split()))

motimono=[]

ans=[]

if k>=n:

    k-=n

    heapify(v)

    ans.append(sum(v))

    for i in range(k):

        if len(v)>0:

            heappop(v)

        ans.append(sum(v))

    print((max(ans)))

else:

    v*=2

    for j in range(1,k+1):

        for i in range(n-j,n+1):

            motimono=v[i:i+j]

            ans.append(sum(motimono))

            heapify(motimono)

            for i in range(k-j):

                if len(motimono)>0:

                    heappop(motimono)

                ans.append(sum(motimono))

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

*v,=list(map(int,input().split()))

motimono=[]

ans=[]

if k>=n:

    k-=n

    ans.append(sum(v))

    v.sort()

    for i in range(min(k,len(v))):

        v[i]=0

        ans.append(sum(v))

    print((max(ans)))

else:

    v*=2

    for j in range(1,k+1):

        for i in range(n-j,n+1):

            motimono=v[i:i+j]

            ans.append(sum(motimono))

            motimono.sort()

            for i in range(min(k-j,len(motimono))):

                motimono[i]=0

                ans.append(sum(motimono))

    print((max(ans)))

from heapq import *

n, k = list(map(int, input().split()))
(*v,) = list(map(int, input().split()))
motimono = []
ans = []
if k >= n:
    k -= n
    heapify(v)
    ans.append(sum(v))
    for i in range(k):
        if len(v) > 0:
            heappop(v)
        ans.append(sum(v))
    print((max(ans)))
else:
    v *= 2
    for j in range(1, k + 1):
        for i in range(n - j, n + 1):
            motimono = v[i : i + j]
            ans.append(sum(motimono))
            heapify(motimono)
            for i in range(k - j):
                if len(motimono) > 0:
                    heappop(motimono)
                ans.append(sum(motimono))
    print((max(ans)))

n, k = list(map(int, input().split()))
(*v,) = list(map(int, input().split()))
motimono = []
ans = []
if k >= n:
    k -= n
    ans.append(sum(v))
    v.sort()
    for i in range(min(k, len(v))):
        v[i] = 0
        ans.append(sum(v))
    print((max(ans)))
else:
    v *= 2
    for j in range(1, k + 1):
        for i in range(n - j, n + 1):
            motimono = v[i : i + j]
            ans.append(sum(motimono))
            motimono.sort()
            for i in range(min(k - j, len(motimono))):
                motimono[i] = 0
                ans.append(sum(motimono))
    print((max(ans)))

-from heapq import * - -    heapify(v) -    for i in range(k): -        if len(v) > 0: -            heappop(v) +    v.sort() +    for i in range(min(k, len(v))): +        v[i] = 0 -            heapify(motimono) -            for i in range(k - j): -                if len(motimono) > 0: -                    heappop(motimono) +            motimono.sort() +            for i in range(min(k - j, len(motimono))): +                motimono[i] = 0