n, k = map(int, input().split())
l = list(map(int, input().split()))
ans = 0
for i in range(1, min(n, k) + 1):
  for j in range(i + 1):
    l_tmp = l[:j] + l[n - i + j:]
    l_tmp.sort()
    for m in range(min(k - i, i)):
      if l_tmp[m] < 0:
        l_tmp[m] = 0
    ans = max(ans, sum(l_tmp))
print(ans) n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k l = list(map(int, input().split())) l 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(1, min(n, k) + 1):
  for j in range(i + 1):
    l_tmp = l[:j] + l[n - i + j:]
    l_tmp.sort()
    for m in range(min(k - i, i)):
      if l_tmp[m] < 0:
        l_tmp[m] = 0
    ans = max(ans, sum(l_tmp)) i range(1, min(n, k) + 1) range 1 min(n, k) + 1 min(n, k) min n k 1 for j in range(i + 1):
    l_tmp = l[:j] + l[n - i + j:]
    l_tmp.sort()
    for m in range(min(k - i, i)):
      if l_tmp[m] < 0:
        l_tmp[m] = 0
    ans = max(ans, sum(l_tmp)) j range(i + 1) range i + 1 i 1 l_tmp = l[:j] + l[n - i + j:] l_tmp l[:j] + l[n - i + j:] l[:j] l :j j l[n - i + j:] l n - i + j: n - i + j n - i n i j l_tmp.sort() l_tmp.sort l_tmp sort for m in range(min(k - i, i)):
      if l_tmp[m] < 0:
        l_tmp[m] = 0
     m range(min(k - i, i)) range min(k - i, i) min k - i k i i if l_tmp[m] < 0:
        l_tmp[m] = 0
     l_tmp[m] < 0 l_tmp[m] l_tmp m 0 l_tmp[m] = 0 l_tmp[m] l_tmp m 0 ans = max(ans, sum(l_tmp)) ans max(ans, sum(l_tmp)) max ans sum(l_tmp) sum l_tmp print(ans) print ans l_tmp = l[:j] + l[n - i + j:] l[:j] + l[n - i + j:] l_tmp ans = max(ans, sum(l_tmp)) max(ans, sum(l_tmp)) ans l = list(map(int, input().split())) list(map(int, input().split())) l ans = 0 0 ans k = map(int, input().split()) map(int, input().split()) k n, k = map(int, input().split()) map(int, input().split()) n
n, k = map(int, input().split())
l = list(map(int, input().split()))
ans = 0
for i in range(1, min(n, k) + 1):
  for j in range(i + 1):
    l_tmp = l[:j] + l[n - i + j:]
    l_tmp.sort()
    for m in range(min(k - i, i)):
      if l_tmp[m] < 0:
        l_tmp[m] = 0
    ans = max(ans, sum(l_tmp))
print(ans)