from sys import stdin
from collections import deque
N,K = [int(x) for x in stdin.readline().rstrip().split()]
V = [int(x) for x in stdin.readline().rstrip().split()]
ans = 0
rev_V = V[::-1]

for L in range(0, K+1):
        for R in range(0, K+1):
            if L + R > min(K,N):
                break
            
            tmp = V[0:L] + rev_V[0:R]
            tmp.sort()
            tmp = deque(tmp)
            num = K - (L+R)
            stone = -1
            cnt = 0
            while stone < 0:
                if cnt >= num or len(tmp) == 0:
                    break
                stone = tmp.popleft()
                if stone >= 0:
                    tmp.append(stone)
                    break
                cnt += 1
            ans = max(ans, sum(tmp))

print(ans) from sys import stdin from collections import deque int(x) for x in stdin.readline().rstrip().split() for x in stdin.readline().rstrip().split() x stdin.readline().rstrip().split() stdin.readline().rstrip().split stdin.readline().rstrip() stdin.readline().rstrip stdin.readline() stdin.readline stdin readline rstrip split for x in stdin.readline().rstrip().split() int(x) int x N,K = [int(x) for x in stdin.readline().rstrip().split()] N [int(x) for x in stdin.readline().rstrip().split()] K int(x) for x in stdin.readline().rstrip().split() for x in stdin.readline().rstrip().split() x stdin.readline().rstrip().split() stdin.readline().rstrip().split stdin.readline().rstrip() stdin.readline().rstrip stdin.readline() stdin.readline stdin readline rstrip split for x in stdin.readline().rstrip().split() int(x) int x V = [int(x) for x in stdin.readline().rstrip().split()] V [int(x) for x in stdin.readline().rstrip().split()] ans = 0 ans 0 rev_V = V[::-1] rev_V V[::-1] V ::-1 -1 for L in range(0, K+1):
        for R in range(0, K+1):
            if L + R > min(K,N):
                break
            
            tmp = V[0:L] + rev_V[0:R]
            tmp.sort()
            tmp = deque(tmp)
            num = K - (L+R)
            stone = -1
            cnt = 0
            while stone < 0:
                if cnt >= num or len(tmp) == 0:
                    break
                stone = tmp.popleft()
                if stone >= 0:
                    tmp.append(stone)
                    break
                cnt += 1
            ans = max(ans, sum(tmp)) L range(0, K+1) range 0 K+1 K 1 for R in range(0, K+1):
            if L + R > min(K,N):
                break
            
            tmp = V[0:L] + rev_V[0:R]
            tmp.sort()
            tmp = deque(tmp)
            num = K - (L+R)
            stone = -1
            cnt = 0
            while stone < 0:
                if cnt >= num or len(tmp) == 0:
                    break
                stone = tmp.popleft()
                if stone >= 0:
                    tmp.append(stone)
                    break
                cnt += 1
            ans = max(ans, sum(tmp)) R range(0, K+1) range 0 K+1 K 1 if L + R > min(K,N):
                break
            
             L + R > min(K,N) L + R L R min(K,N) min K N break tmp = V[0:L] + rev_V[0:R] tmp V[0:L] + rev_V[0:R] V[0:L] V 0:L 0 L rev_V[0:R] rev_V 0:R 0 R tmp.sort() tmp.sort tmp sort tmp = deque(tmp) tmp deque(tmp) deque tmp num = K - (L+R) num K - (L+R) K L+R L R stone = -1 stone -1 cnt = 0 cnt 0 while stone < 0:
                if cnt >= num or len(tmp) == 0:
                    break
                stone = tmp.popleft()
                if stone >= 0:
                    tmp.append(stone)
                    break
                cnt += 1
             stone < 0 stone 0 if cnt >= num or len(tmp) == 0:
                    break
                 cnt >= num or len(tmp) == 0 cnt >= num cnt num len(tmp) == 0 len(tmp) len tmp 0 break stone = tmp.popleft() stone tmp.popleft() tmp.popleft tmp popleft if stone >= 0:
                    tmp.append(stone)
                    break
                 stone >= 0 stone 0 tmp.append(stone) tmp.append tmp append stone break cnt += 1 cnt 1 ans = max(ans, sum(tmp)) ans max(ans, sum(tmp)) max ans sum(tmp) sum tmp print(ans) print ans tmp = deque(tmp) deque(tmp) tmp ans = max(ans, sum(tmp)) max(ans, sum(tmp)) ans K = [int(x) for x in stdin.readline().rstrip().split()] [int(x) for x in stdin.readline().rstrip().split()] K cnt += 1 1 cnt cnt = 0 0 cnt tmp = V[0:L] + rev_V[0:R] V[0:L] + rev_V[0:R] tmp stone = tmp.popleft() tmp.popleft() stone ans = 0 0 ans V = [int(x) for x in stdin.readline().rstrip().split()] [int(x) for x in stdin.readline().rstrip().split()] V stone = -1 -1 stone rev_V = V[::-1] V[::-1] rev_V N,K = [int(x) for x in stdin.readline().rstrip().split()] [int(x) for x in stdin.readline().rstrip().split()] N num = K - (L+R) K - (L+R) num
from sys import stdin
from collections import deque
N,K = [int(x) for x in stdin.readline().rstrip().split()]
V = [int(x) for x in stdin.readline().rstrip().split()]
ans = 0
rev_V = V[::-1]

for L in range(0, K+1):
        for R in range(0, K+1):
            if L + R > min(K,N):
                break
            
            tmp = V[0:L] + rev_V[0:R]
            tmp.sort()
            tmp = deque(tmp)
            num = K - (L+R)
            stone = -1
            cnt = 0
            while stone < 0:
                if cnt >= num or len(tmp) == 0:
                    break
                stone = tmp.popleft()
                if stone >= 0:
                    tmp.append(stone)
                    break
                cnt += 1
            ans = max(ans, sum(tmp))

print(ans)