N, K = map(int, input().split())
V = list(map(int, input().split()))
R = min(N, K)
ans = 0
for a in range(R+1):
  for b in range(R+1-a): #操作Aをa回、操作Bをb回
    tmp = list()
    for i in range(a): 
      tmp.append(V[i])
    for j in range(b):
      tmp.append(V[N-1-j])
    tmp.sort()
    x = min(K-a-b, len(tmp))
    for k in range(x):
      if(tmp[k] < 0):
        tmp[k] = 0
    ans = max(ans, sum(tmp))
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 R = min(N, K) R min(N, K) min N K ans = 0 ans 0 for a in range(R+1):
  for b in range(R+1-a): #操作Aをa回、操作Bをb回
    tmp = list()
    for i in range(a): 
      tmp.append(V[i])
    for j in range(b):
      tmp.append(V[N-1-j])
    tmp.sort()
    x = min(K-a-b, len(tmp))
    for k in range(x):
      if(tmp[k] < 0):
        tmp[k] = 0
    ans = max(ans, sum(tmp)) a range(R+1) range R+1 R 1 for b in range(R+1-a): #操作Aをa回、操作Bをb回
    tmp = list()
    for i in range(a): 
      tmp.append(V[i])
    for j in range(b):
      tmp.append(V[N-1-j])
    tmp.sort()
    x = min(K-a-b, len(tmp))
    for k in range(x):
      if(tmp[k] < 0):
        tmp[k] = 0
    ans = max(ans, sum(tmp)) b range(R+1-a) range R+1-a R+1 R 1 a tmp = list() tmp list() list for i in range(a): 
      tmp.append(V[i])
     i range(a) range a tmp.append(V[i]) tmp.append tmp append V[i] V i for j in range(b):
      tmp.append(V[N-1-j])
     j range(b) range b tmp.append(V[N-1-j]) tmp.append tmp append V[N-1-j] V N-1-j N-1 N 1 j tmp.sort() tmp.sort tmp sort x = min(K-a-b, len(tmp)) x min(K-a-b, len(tmp)) min K-a-b K-a K a b len(tmp) len tmp for k in range(x):
      if(tmp[k] < 0):
        tmp[k] = 0
     k range(x) range x if(tmp[k] < 0):
        tmp[k] = 0
     tmp[k] < 0 tmp[k] tmp k 0 tmp[k] = 0 tmp[k] tmp k 0 ans = max(ans, sum(tmp)) ans max(ans, sum(tmp)) max ans sum(tmp) sum tmp print(ans) print ans tmp = list() list() tmp N, K = map(int, input().split()) map(int, input().split()) N ans = max(ans, sum(tmp)) max(ans, sum(tmp)) ans R = min(N, K) min(N, K) R K = map(int, input().split()) map(int, input().split()) K ans = 0 0 ans V = list(map(int, input().split())) list(map(int, input().split())) V x = min(K-a-b, len(tmp)) min(K-a-b, len(tmp)) x
N, K = map(int, input().split())
V = list(map(int, input().split()))
R = min(N, K)
ans = 0
for a in range(R+1):
  for b in range(R+1-a): #操作Aをa回、操作Bをb回
    tmp = list()
    for i in range(a): 
      tmp.append(V[i])
    for j in range(b):
      tmp.append(V[N-1-j])
    tmp.sort()
    x = min(K-a-b, len(tmp))
    for k in range(x):
      if(tmp[k] < 0):
        tmp[k] = 0
    ans = max(ans, sum(tmp))
print(ans)