n,k=[int(x) for x in input().rstrip().split()]
v=[int(x) for x in input().rstrip().split()]
vr=v[::-1]
ans=0
mi=min(n,k)

for i in range(mi+1):
  for j in range(mi-i+1):
    minus=0
    now=v[:i]+vr[:j]
    d=k-(len(now))
    now.sort()
    md=min(d,len(now))
    for s in range(md):
      if 0<=now[s]:
        break
      minus+=now[s]

    ans=max(ans,sum(now)-minus)
print(ans) int(x) for x in input().rstrip().split() for x in input().rstrip().split() x input().rstrip().split() ().rstrip().split ().rstrip() ().rstrip () input rstrip split for x in input().rstrip().split() int(x) int x n,k=[int(x) for x in input().rstrip().split()] n [int(x) for x in input().rstrip().split()] k int(x) for x in input().rstrip().split() for x in input().rstrip().split() x input().rstrip().split() ().rstrip().split ().rstrip() ().rstrip () input rstrip split for x in input().rstrip().split() int(x) int x v=[int(x) for x in input().rstrip().split()] v [int(x) for x in input().rstrip().split()] vr=v[::-1] vr v[::-1] v ::-1 -1 ans=0 ans 0 mi=min(n,k) mi min(n,k) min n k for i in range(mi+1):
  for j in range(mi-i+1):
    minus=0
    now=v[:i]+vr[:j]
    d=k-(len(now))
    now.sort()
    md=min(d,len(now))
    for s in range(md):
      if 0<=now[s]:
        break
      minus+=now[s]

    ans=max(ans,sum(now)-minus) i range(mi+1) range mi+1 mi 1 for j in range(mi-i+1):
    minus=0
    now=v[:i]+vr[:j]
    d=k-(len(now))
    now.sort()
    md=min(d,len(now))
    for s in range(md):
      if 0<=now[s]:
        break
      minus+=now[s]

    ans=max(ans,sum(now)-minus) j range(mi-i+1) range mi-i+1 mi-i mi i 1 minus=0 minus 0 now=v[:i]+vr[:j] now v[:i]+vr[:j] v[:i] v :i i vr[:j] vr :j j d=k-(len(now)) d k-(len(now)) k len(now) len now now.sort() now.sort now sort md=min(d,len(now)) md min(d,len(now)) min d len(now) len now for s in range(md):
      if 0<=now[s]:
        break
      minus+=now[s]

     s range(md) range md if 0<=now[s]:
        break
       0<=now[s] 0 now[s] now s break minus+=now[s] minus now[s] now s ans=max(ans,sum(now)-minus) ans max(ans,sum(now)-minus) max ans sum(now)-minus sum(now) sum now minus print(ans) print ans vr=v[::-1] v[::-1] vr now=v[:i]+vr[:j] v[:i]+vr[:j] now md=min(d,len(now)) min(d,len(now)) md mi=min(n,k) min(n,k) mi minus=0 0 minus d=k-(len(now)) k-(len(now)) d ans=max(ans,sum(now)-minus) max(ans,sum(now)-minus) ans v=[int(x) for x in input().rstrip().split()] [int(x) for x in input().rstrip().split()] v ans=0 0 ans k=[int(x) for x in input().rstrip().split()] [int(x) for x in input().rstrip().split()] k n,k=[int(x) for x in input().rstrip().split()] [int(x) for x in input().rstrip().split()] n minus+=now[s] now[s] minus
n,k=[int(x) for x in input().rstrip().split()]
v=[int(x) for x in input().rstrip().split()]
vr=v[::-1]
ans=0
mi=min(n,k)

for i in range(mi+1):
  for j in range(mi-i+1):
    minus=0
    now=v[:i]+vr[:j]
    d=k-(len(now))
    now.sort()
    md=min(d,len(now))
    for s in range(md):
      if 0<=now[s]:
        break
      minus+=now[s]

    ans=max(ans,sum(now)-minus)
print(ans)