import heapq
from collections import deque
from functools import lru_cache

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

for l in range(0,K + 1):
  for r in range(0,K - l + 1):
    d = K - r - l
    tmp = 0
    have = []
    if l + r > N:
      continue
    for i in range(0,l):
      tmp += V[i]
      have.append(V[i])
    for j in range(N - r,N):
      tmp += V[j]
      have.append(V[j])
    h = len(have)
    #print(have)
    have = sorted(have)
    for k in range(0,d):
      #print(have,sum(have))
      if k >= h:
        break
      if have[k] > 0:
        break
      tmp -= have[k]
    ans = max(tmp,ans)
    
print(ans) import heapq heapq from collections import deque from functools import lru_cache 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 l in range(0,K + 1):
  for r in range(0,K - l + 1):
    d = K - r - l
    tmp = 0
    have = []
    if l + r > N:
      continue
    for i in range(0,l):
      tmp += V[i]
      have.append(V[i])
    for j in range(N - r,N):
      tmp += V[j]
      have.append(V[j])
    h = len(have)
    #print(have)
    have = sorted(have)
    for k in range(0,d):
      #print(have,sum(have))
      if k >= h:
        break
      if have[k] > 0:
        break
      tmp -= have[k]
    ans = max(tmp,ans)
     l range(0,K + 1) range 0 K + 1 K 1 for r in range(0,K - l + 1):
    d = K - r - l
    tmp = 0
    have = []
    if l + r > N:
      continue
    for i in range(0,l):
      tmp += V[i]
      have.append(V[i])
    for j in range(N - r,N):
      tmp += V[j]
      have.append(V[j])
    h = len(have)
    #print(have)
    have = sorted(have)
    for k in range(0,d):
      #print(have,sum(have))
      if k >= h:
        break
      if have[k] > 0:
        break
      tmp -= have[k]
    ans = max(tmp,ans)
     r range(0,K - l + 1) range 0 K - l + 1 K - l K l 1 d = K - r - l d K - r - l K - r K r l tmp = 0 tmp 0 have = [] have [] if l + r > N:
      continue
     l + r > N l + r l r N continue for i in range(0,l):
      tmp += V[i]
      have.append(V[i])
     i range(0,l) range 0 l tmp += V[i] tmp V[i] V i have.append(V[i]) have.append have append V[i] V i for j in range(N - r,N):
      tmp += V[j]
      have.append(V[j])
     j range(N - r,N) range N - r N r N tmp += V[j] tmp V[j] V j have.append(V[j]) have.append have append V[j] V j h = len(have) h len(have) len have have = sorted(have) have sorted(have) sorted have for k in range(0,d):
      #print(have,sum(have))
      if k >= h:
        break
      if have[k] > 0:
        break
      tmp -= have[k]
     k range(0,d) range 0 d if k >= h:
        break
       k >= h k h break if have[k] > 0:
        break
       have[k] > 0 have[k] have k 0 break tmp -= have[k] tmp have[k] have k ans = max(tmp,ans) ans max(tmp,ans) max tmp ans print(ans) print ans V = list(map(int,input().split())) list(map(int,input().split())) V ans = max(tmp,ans) max(tmp,ans) ans N,K = map(int,input().split()) map(int,input().split()) N h = len(have) len(have) h have = sorted(have) sorted(have) have ans = 0 0 ans tmp -= have[k] have[k] tmp have = [] [] have tmp += V[i] V[i] tmp tmp += V[j] V[j] tmp K = map(int,input().split()) map(int,input().split()) K tmp = 0 0 tmp d = K - r - l K - r - l d
import heapq
from collections import deque
from functools import lru_cache

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

for l in range(0,K + 1):
  for r in range(0,K - l + 1):
    d = K - r - l
    tmp = 0
    have = []
    if l + r > N:
      continue
    for i in range(0,l):
      tmp += V[i]
      have.append(V[i])
    for j in range(N - r,N):
      tmp += V[j]
      have.append(V[j])
    h = len(have)
    #print(have)
    have = sorted(have)
    for k in range(0,d):
      #print(have,sum(have))
      if k >= h:
        break
      if have[k] > 0:
        break
      tmp -= have[k]
    ans = max(tmp,ans)
    
print(ans)
