n, k = map(int, input().split())
v = list(map(int, input().split()))
ans = 0
for i in range(k+1):
  for j in range(k+1):
    if i+j > k or i+j > n:
      continue
    t = k-(i+j)
    s = v[:i] + v[(n-j):]
    s.sort()
    u = 0
    while u < t:
      u += 1
      if len(s) < 1:
        break
      if s[0] < 0:
        s.pop(0)
      else:
        break
    ans = max(ans, sum(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 ans = 0 ans 0 for i in range(k+1):
  for j in range(k+1):
    if i+j > k or i+j > n:
      continue
    t = k-(i+j)
    s = v[:i] + v[(n-j):]
    s.sort()
    u = 0
    while u < t:
      u += 1
      if len(s) < 1:
        break
      if s[0] < 0:
        s.pop(0)
      else:
        break
    ans = max(ans, sum(s)) i range(k+1) range k+1 k 1 for j in range(k+1):
    if i+j > k or i+j > n:
      continue
    t = k-(i+j)
    s = v[:i] + v[(n-j):]
    s.sort()
    u = 0
    while u < t:
      u += 1
      if len(s) < 1:
        break
      if s[0] < 0:
        s.pop(0)
      else:
        break
    ans = max(ans, sum(s)) j range(k+1) range k+1 k 1 if i+j > k or i+j > n:
      continue
     i+j > k or i+j > n i+j > k i+j i j k i+j > n i+j i j n continue t = k-(i+j) t k-(i+j) k i+j i j s = v[:i] + v[(n-j):] s v[:i] + v[(n-j):] v[:i] v :i i v[(n-j):] v (n-j): n-j n j s.sort() s.sort s sort u = 0 u 0 while u < t:
      u += 1
      if len(s) < 1:
        break
      if s[0] < 0:
        s.pop(0)
      else:
        break
     u < t u t u += 1 u 1 if len(s) < 1:
        break
       len(s) < 1 len(s) len s 1 break if s[0] < 0:
        s.pop(0)
      else:
        break
     s[0] < 0 s[0] s 0 0 s.pop(0) s.pop s pop 0 break ans = max(ans, sum(s)) ans max(ans, sum(s)) max ans sum(s) sum s print (ans) print ans u += 1 1 u ans = max(ans, sum(s)) max(ans, sum(s)) ans ans = 0 0 ans v = list(map(int, input().split())) list(map(int, input().split())) v s = v[:i] + v[(n-j):] v[:i] + v[(n-j):] s u = 0 0 u k = map(int, input().split()) map(int, input().split()) k n, k = map(int, input().split()) map(int, input().split()) n t = k-(i+j) k-(i+j) t
n, k = map(int, input().split())
v = list(map(int, input().split()))
ans = 0
for i in range(k+1):
  for j in range(k+1):
    if i+j > k or i+j > n:
      continue
    t = k-(i+j)
    s = v[:i] + v[(n-j):]
    s.sort()
    u = 0
    while u < t:
      u += 1
      if len(s) < 1:
        break
      if s[0] < 0:
        s.pop(0)
      else:
        break
    ans = max(ans, sum(s))
print (ans)