import heapq 

N,K = map(int,input().split())
A = list(map(int,input().split()))
m = min(N,K) #KがNより大きい場合を防ぐ
M = 0 
for i in range(m+1):
    for j in range(m-i+1):
        A1 = A[:i]
        A3 = A[N-j:]
        new_A = A1+A3
        heapq.heapify(new_A)
        h = K - len(new_A)
        while new_A  and h >0:
            q = heapq.heappop(new_A)
            h-=1
            if q > 0:
                heapq.heappush(new_A,q)
                break
        M = max(M,sum(new_A))
print(M) import heapq heapq N,K = map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split K A = list(map(int,input().split())) A list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split m = min(N,K) m min(N,K) min N K M = 0 M 0 for i in range(m+1):
    for j in range(m-i+1):
        A1 = A[:i]
        A3 = A[N-j:]
        new_A = A1+A3
        heapq.heapify(new_A)
        h = K - len(new_A)
        while new_A  and h >0:
            q = heapq.heappop(new_A)
            h-=1
            if q > 0:
                heapq.heappush(new_A,q)
                break
        M = max(M,sum(new_A)) i range(m+1) range m+1 m 1 for j in range(m-i+1):
        A1 = A[:i]
        A3 = A[N-j:]
        new_A = A1+A3
        heapq.heapify(new_A)
        h = K - len(new_A)
        while new_A  and h >0:
            q = heapq.heappop(new_A)
            h-=1
            if q > 0:
                heapq.heappush(new_A,q)
                break
        M = max(M,sum(new_A)) j range(m-i+1) range m-i+1 m-i m i 1 A1 = A[:i] A1 A[:i] A :i i A3 = A[N-j:] A3 A[N-j:] A N-j: N-j N j new_A = A1+A3 new_A A1+A3 A1 A3 heapq.heapify(new_A) heapq.heapify heapq heapify new_A h = K - len(new_A) h K - len(new_A) K len(new_A) len new_A while new_A  and h >0:
            q = heapq.heappop(new_A)
            h-=1
            if q > 0:
                heapq.heappush(new_A,q)
                break
         new_A  and h >0 new_A h >0 h 0 q = heapq.heappop(new_A) q heapq.heappop(new_A) heapq.heappop heapq heappop new_A h-=1 h 1 if q > 0:
                heapq.heappush(new_A,q)
                break
         q > 0 q 0 heapq.heappush(new_A,q) heapq.heappush heapq heappush new_A q break M = max(M,sum(new_A)) M max(M,sum(new_A)) max M sum(new_A) sum new_A print(M) print M N,K = map(int,input().split()) map(int,input().split()) N K = map(int,input().split()) map(int,input().split()) K m = min(N,K) min(N,K) m h = K - len(new_A) K - len(new_A) h A = list(map(int,input().split())) list(map(int,input().split())) A M = 0 0 M A3 = A[N-j:] A[N-j:] A3 new_A = A1+A3 A1+A3 new_A q = heapq.heappop(new_A) heapq.heappop(new_A) q M = max(M,sum(new_A)) max(M,sum(new_A)) M A1 = A[:i] A[:i] A1 h-=1 1 h
import heapq 

N,K = map(int,input().split())
A = list(map(int,input().split()))
m = min(N,K) #KがNより大きい場合を防ぐ
M = 0 
for i in range(m+1):
    for j in range(m-i+1):
        A1 = A[:i]
        A3 = A[N-j:]
        new_A = A1+A3
        heapq.heapify(new_A)
        h = K - len(new_A)
        while new_A  and h >0:
            q = heapq.heappop(new_A)
            h-=1
            if q > 0:
                heapq.heappush(new_A,q)
                break
        M = max(M,sum(new_A))
print(M)