import sys
input = sys.stdin.readline

N,K = (int(x) for x in input().rstrip('\n').split())
vs = [int(x) for x in input().rstrip('\n').split()]
g = [vs[0],vs[-1]]
rest = K
for k in [K-1,K]:
  for b in range(K//2):
    t = k-b
    if t>N:
      t=N
    for i in range(t+1):
      v = []
      if i <t:
        v.extend(vs[:i])
        v.extend(vs[-(t-i):])
        for _ in range(b):
          if min(v)<0:
            v.remove(min(v))
          else:
            break
      else:
        v.extend(vs[:t])
        for _ in range(b):
          if min(v)<0:
          	v.remove(min(v))
      g.append(sum(v))
if max(g)<0:
  print(0)
else:
  print(max(g)) import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline int(x) for x in input().rstrip('\n').split() for x in input().rstrip('\n').split() x input().rstrip('\n').split() ().rstrip('\n').split ().rstrip('\n') ().rstrip () input rstrip '\n' split for x in input().rstrip('\n').split() int(x) int x N,K = (int(x) for x in input().rstrip('\n').split()) N (int(x) for x in input().rstrip('\n').split()) K int(x) for x in input().rstrip('\n').split() for x in input().rstrip('\n').split() x input().rstrip('\n').split() ().rstrip('\n').split ().rstrip('\n') ().rstrip () input rstrip '\n' split for x in input().rstrip('\n').split() int(x) int x vs = [int(x) for x in input().rstrip('\n').split()] vs [int(x) for x in input().rstrip('\n').split()] g = [vs[0],vs[-1]] g [vs[0],vs[-1]] vs[0] vs 0 vs[-1] vs -1 rest = K rest K for k in [K-1,K]:
  for b in range(K//2):
    t = k-b
    if t>N:
      t=N
    for i in range(t+1):
      v = []
      if i <t:
        v.extend(vs[:i])
        v.extend(vs[-(t-i):])
        for _ in range(b):
          if min(v)<0:
            v.remove(min(v))
          else:
            break
      else:
        v.extend(vs[:t])
        for _ in range(b):
          if min(v)<0:
          	v.remove(min(v))
      g.append(sum(v)) k [K-1,K] K-1 K 1 K for b in range(K//2):
    t = k-b
    if t>N:
      t=N
    for i in range(t+1):
      v = []
      if i <t:
        v.extend(vs[:i])
        v.extend(vs[-(t-i):])
        for _ in range(b):
          if min(v)<0:
            v.remove(min(v))
          else:
            break
      else:
        v.extend(vs[:t])
        for _ in range(b):
          if min(v)<0:
          	v.remove(min(v))
      g.append(sum(v)) b range(K//2) range K//2 K 2 t = k-b t k-b k b if t>N:
      t=N
     t>N t N t=N t N for i in range(t+1):
      v = []
      if i <t:
        v.extend(vs[:i])
        v.extend(vs[-(t-i):])
        for _ in range(b):
          if min(v)<0:
            v.remove(min(v))
          else:
            break
      else:
        v.extend(vs[:t])
        for _ in range(b):
          if min(v)<0:
          	v.remove(min(v))
      g.append(sum(v)) i range(t+1) range t+1 t 1 v = [] v [] if i <t:
        v.extend(vs[:i])
        v.extend(vs[-(t-i):])
        for _ in range(b):
          if min(v)<0:
            v.remove(min(v))
          else:
            break
      else:
        v.extend(vs[:t])
        for _ in range(b):
          if min(v)<0:
          	v.remove(min(v))
       i <t i t v.extend(vs[:i]) v.extend v extend vs[:i] vs :i i v.extend(vs[-(t-i):]) v.extend v extend vs[-(t-i):] vs -(t-i): -(t-i) t-i t i for _ in range(b):
          if min(v)<0:
            v.remove(min(v))
          else:
            break
       _ range(b) range b if min(v)<0:
            v.remove(min(v))
          else:
            break
       min(v)<0 min(v) min v 0 v.remove(min(v)) v.remove v remove min(v) min v break v.extend(vs[:t]) v.extend v extend vs[:t] vs :t t for _ in range(b):
          if min(v)<0:
          	v.remove(min(v))
       _ range(b) range b if min(v)<0:
          	v.remove(min(v))
       min(v)<0 min(v) min v 0 v.remove(min(v)) v.remove v remove min(v) min v g.append(sum(v)) g.append g append sum(v) sum v if max(g)<0:
  print(0)
else:
  print(max(g)) max(g)<0 max(g) max g 0 print(0) print 0 print(max(g)) print max(g) max g K = (int(x) for x in input().rstrip('\n').split()) (int(x) for x in input().rstrip('\n').split()) K N,K = (int(x) for x in input().rstrip('\n').split()) (int(x) for x in input().rstrip('\n').split()) N v = [] [] v vs = [int(x) for x in input().rstrip('\n').split()] [int(x) for x in input().rstrip('\n').split()] vs t = k-b k-b t g = [vs[0],vs[-1]] [vs[0],vs[-1]] g t=N N t input = sys.stdin.readline sys.stdin.readline input rest = K K rest
import sys
input = sys.stdin.readline

N,K = (int(x) for x in input().rstrip('\n').split())
vs = [int(x) for x in input().rstrip('\n').split()]
g = [vs[0],vs[-1]]
rest = K
for k in [K-1,K]:
  for b in range(K//2):
    t = k-b
    if t>N:
      t=N
    for i in range(t+1):
      v = []
      if i <t:
        v.extend(vs[:i])
        v.extend(vs[-(t-i):])
        for _ in range(b):
          if min(v)<0:
            v.remove(min(v))
          else:
            break
      else:
        v.extend(vs[:t])
        for _ in range(b):
          if min(v)<0:
          	v.remove(min(v))
      g.append(sum(v))
if max(g)<0:
  print(0)
else:
  print(max(g))