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