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

for i in range(M+1):
  for j in range(M-i+1):
    G = V[:i]+V[N-j:]
    G.sort()
    for j in range(K-i-j+1):
      ans = max(ans,sum(G[j:]))

print(ans) 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 M = min(N,K) M min(N,K) min N K ans = 0 ans 0 for i in range(M+1):
  for j in range(M-i+1):
    G = V[:i]+V[N-j:]
    G.sort()
    for j in range(K-i-j+1):
      ans = max(ans,sum(G[j:])) i range(M+1) range M+1 M 1 for j in range(M-i+1):
    G = V[:i]+V[N-j:]
    G.sort()
    for j in range(K-i-j+1):
      ans = max(ans,sum(G[j:])) j range(M-i+1) range M-i+1 M-i M i 1 G = V[:i]+V[N-j:] G V[:i]+V[N-j:] V[:i] V :i i V[N-j:] V N-j: N-j N j G.sort() G.sort G sort for j in range(K-i-j+1):
      ans = max(ans,sum(G[j:])) j range(K-i-j+1) range K-i-j+1 K-i-j K-i K i j 1 ans = max(ans,sum(G[j:])) ans max(ans,sum(G[j:])) max ans sum(G[j:]) sum G[j:] G j: j print(ans) print ans G = V[:i]+V[N-j:] V[:i]+V[N-j:] G K = map(int,input().split()) map(int,input().split()) K ans = 0 0 ans M = min(N,K) min(N,K) M V = list(map(int,input().split())) list(map(int,input().split())) V ans = max(ans,sum(G[j:])) max(ans,sum(G[j:])) ans N,K = map(int,input().split()) map(int,input().split()) N
N,K = map(int,input().split())
V = list(map(int,input().split()))
M = min(N,K)
ans = 0

for i in range(M+1):
  for j in range(M-i+1):
    G = V[:i]+V[N-j:]
    G.sort()
    for j in range(K-i-j+1):
      ans = max(ans,sum(G[j:]))

print(ans)