n,k = map(int,input().split())
v = list(map(int,input().split()))
r = min(n,k)
ans = -10**10
for i in range(0,r+1):
  for a in range(i+1):
    b = i - a
    val = sorted(v[:a]+v[(n-b):])
    s = sum(val)
    for j in range(min(k-i,len(val))):
      if val[j] < 0:
        s -= val[j]
      else:
        break
    ans = max(ans,s)
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 = -10**10 ans -10**10 -10 10 for i in range(0,r+1):
  for a in range(i+1):
    b = i - a
    val = sorted(v[:a]+v[(n-b):])
    s = sum(val)
    for j in range(min(k-i,len(val))):
      if val[j] < 0:
        s -= val[j]
      else:
        break
    ans = max(ans,s) i range(0,r+1) range 0 r+1 r 1 for a in range(i+1):
    b = i - a
    val = sorted(v[:a]+v[(n-b):])
    s = sum(val)
    for j in range(min(k-i,len(val))):
      if val[j] < 0:
        s -= val[j]
      else:
        break
    ans = max(ans,s) a range(i+1) range i+1 i 1 b = i - a b i - a i a val = sorted(v[:a]+v[(n-b):]) val sorted(v[:a]+v[(n-b):]) sorted v[:a]+v[(n-b):] v[:a] v :a a v[(n-b):] v (n-b): n-b n b s = sum(val) s sum(val) sum val for j in range(min(k-i,len(val))):
      if val[j] < 0:
        s -= val[j]
      else:
        break
     j range(min(k-i,len(val))) range min(k-i,len(val)) min k-i k i len(val) len val if val[j] < 0:
        s -= val[j]
      else:
        break
     val[j] < 0 val[j] val j 0 s -= val[j] s val[j] val j break ans = max(ans,s) ans max(ans,s) max ans s print(ans) print ans ans = -10**10 -10**10 ans ans = max(ans,s) max(ans,s) ans val = sorted(v[:a]+v[(n-b):]) sorted(v[:a]+v[(n-b):]) val r = min(n,k) min(n,k) r b = i - a i - a b s = sum(val) sum(val) s s -= val[j] val[j] s n,k = map(int,input().split()) map(int,input().split()) n v = list(map(int,input().split())) list(map(int,input().split())) v k = map(int,input().split()) map(int,input().split()) k
n,k = map(int,input().split())
v = list(map(int,input().split()))
r = min(n,k)
ans = -10**10
for i in range(0,r+1):
  for a in range(i+1):
    b = i - a
    val = sorted(v[:a]+v[(n-b):])
    s = sum(val)
    for j in range(min(k-i,len(val))):
      if val[j] < 0:
        s -= val[j]
      else:
        break
    ans = max(ans,s)
print(ans)