import heapq
n,k = map(int, input().split())
v = list(map(int, input().split()))
ans = 0
for left in range(n+1):
    for right in range(left, n+1):
        have = []
        heapq.heapify(have)
        i = 0
        while i < left:
            heapq.heappush(have, v[i])
            i += 1
        cost = left + (n - right)
        if cost > k:
            continue
        i = n-1
        while i >= right:
            heapq.heappush(have, v[i])
            i -= 1
        while k - cost > 0 and len(have) > 0:
            value = heapq.heappop(have)
            if  value >= 0:
                heapq.heappush(have,value)
                break
            cost += 1
        #print("left:{} right:{} ans:{}".format(left, right, sum(have)))
        ans = max(ans, sum(have))
print(ans)

 import heapq heapq n,k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k v = list(map(int, input().split())) v list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split ans = 0 ans 0 for left in range(n+1):
    for right in range(left, n+1):
        have = []
        heapq.heapify(have)
        i = 0
        while i < left:
            heapq.heappush(have, v[i])
            i += 1
        cost = left + (n - right)
        if cost > k:
            continue
        i = n-1
        while i >= right:
            heapq.heappush(have, v[i])
            i -= 1
        while k - cost > 0 and len(have) > 0:
            value = heapq.heappop(have)
            if  value >= 0:
                heapq.heappush(have,value)
                break
            cost += 1
        #print("left:{} right:{} ans:{}".format(left, right, sum(have)))
        ans = max(ans, sum(have)) left range(n+1) range n+1 n 1 for right in range(left, n+1):
        have = []
        heapq.heapify(have)
        i = 0
        while i < left:
            heapq.heappush(have, v[i])
            i += 1
        cost = left + (n - right)
        if cost > k:
            continue
        i = n-1
        while i >= right:
            heapq.heappush(have, v[i])
            i -= 1
        while k - cost > 0 and len(have) > 0:
            value = heapq.heappop(have)
            if  value >= 0:
                heapq.heappush(have,value)
                break
            cost += 1
        #print("left:{} right:{} ans:{}".format(left, right, sum(have)))
        ans = max(ans, sum(have)) right range(left, n+1) range left n+1 n 1 have = [] have [] heapq.heapify(have) heapq.heapify heapq heapify have i = 0 i 0 while i < left:
            heapq.heappush(have, v[i])
            i += 1
         i < left i left heapq.heappush(have, v[i]) heapq.heappush heapq heappush have v[i] v i i += 1 i 1 cost = left + (n - right) cost left + (n - right) left n - right n right if cost > k:
            continue
         cost > k cost k continue i = n-1 i n-1 n 1 while i >= right:
            heapq.heappush(have, v[i])
            i -= 1
         i >= right i right heapq.heappush(have, v[i]) heapq.heappush heapq heappush have v[i] v i i -= 1 i 1 while k - cost > 0 and len(have) > 0:
            value = heapq.heappop(have)
            if  value >= 0:
                heapq.heappush(have,value)
                break
            cost += 1
        #print("left:{} right:{} ans:{}".format(left, right, sum(have)))
         k - cost > 0 and len(have) > 0 k - cost > 0 k - cost k cost 0 len(have) > 0 len(have) len have 0 value = heapq.heappop(have) value heapq.heappop(have) heapq.heappop heapq heappop have if  value >= 0:
                heapq.heappush(have,value)
                break
             value >= 0 value 0 heapq.heappush(have,value) heapq.heappush heapq heappush have value break cost += 1 cost 1 ans = max(ans, sum(have)) ans max(ans, sum(have)) max ans sum(have) sum have print(ans) print ans i = n-1 n-1 i k = map(int, input().split()) map(int, input().split()) k ans = max(ans, sum(have)) max(ans, sum(have)) ans i -= 1 1 i v = list(map(int, input().split())) list(map(int, input().split())) v i = 0 0 i have = [] [] have i += 1 1 i value = heapq.heappop(have) heapq.heappop(have) value cost = left + (n - right) left + (n - right) cost ans = 0 0 ans n,k = map(int, input().split()) map(int, input().split()) n cost += 1 1 cost
import heapq
n,k = map(int, input().split())
v = list(map(int, input().split()))
ans = 0
for left in range(n+1):
    for right in range(left, n+1):
        have = []
        heapq.heapify(have)
        i = 0
        while i < left:
            heapq.heappush(have, v[i])
            i += 1
        cost = left + (n - right)
        if cost > k:
            continue
        i = n-1
        while i >= right:
            heapq.heappush(have, v[i])
            i -= 1
        while k - cost > 0 and len(have) > 0:
            value = heapq.heappop(have)
            if  value >= 0:
                heapq.heappush(have,value)
                break
            cost += 1
        #print("left:{} right:{} ans:{}".format(left, right, sum(have)))
        ans = max(ans, sum(have))
print(ans)


