import heapq

n,k=map(int,input().split())
v=list(map(int,input().split()))
s=-10**7-1

if n>k:
    for l in range(k//2+1):
        for i in range(k+1-l):
            d=v[:i]
            d.extend(v[(n-k+l+i):])
            heap=heapq.heapify(d)
            res=sum(d)
            for j in range(l):
                t=heapq.heappop(d)
                if t<0:
                    res-=t
                else:
                    break
            if s<res:
                s=res
else:
    for l in range(n+1):
        for i in range(n-l+1):
            d=v[:i]
            d.extend(v[(l+i):])
            heap=heapq.heapify(d)
            res=sum(d)
            for j in range(k-(n-l)):
                if not d:
                    break
                t=heapq.heappop(d)
                if t<0:
                    res-=t
                else:
                    break
            if s<res:
                s=res

        
if s<0:
    print(0)
else:
    print(s)
         import heapq heapq 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 s=-10**7-1 s -10**7-1 -10**7 -10 7 1 if n>k:
    for l in range(k//2+1):
        for i in range(k+1-l):
            d=v[:i]
            d.extend(v[(n-k+l+i):])
            heap=heapq.heapify(d)
            res=sum(d)
            for j in range(l):
                t=heapq.heappop(d)
                if t<0:
                    res-=t
                else:
                    break
            if s<res:
                s=res
else:
    for l in range(n+1):
        for i in range(n-l+1):
            d=v[:i]
            d.extend(v[(l+i):])
            heap=heapq.heapify(d)
            res=sum(d)
            for j in range(k-(n-l)):
                if not d:
                    break
                t=heapq.heappop(d)
                if t<0:
                    res-=t
                else:
                    break
            if s<res:
                s=res

         n>k n k for l in range(k//2+1):
        for i in range(k+1-l):
            d=v[:i]
            d.extend(v[(n-k+l+i):])
            heap=heapq.heapify(d)
            res=sum(d)
            for j in range(l):
                t=heapq.heappop(d)
                if t<0:
                    res-=t
                else:
                    break
            if s<res:
                s=res l range(k//2+1) range k//2+1 k//2 k 2 1 for i in range(k+1-l):
            d=v[:i]
            d.extend(v[(n-k+l+i):])
            heap=heapq.heapify(d)
            res=sum(d)
            for j in range(l):
                t=heapq.heappop(d)
                if t<0:
                    res-=t
                else:
                    break
            if s<res:
                s=res i range(k+1-l) range k+1-l k+1 k 1 l d=v[:i] d v[:i] v :i i d.extend(v[(n-k+l+i):]) d.extend d extend v[(n-k+l+i):] v (n-k+l+i): n-k+l+i n-k+l n-k n k l i heap=heapq.heapify(d) heap heapq.heapify(d) heapq.heapify heapq heapify d res=sum(d) res sum(d) sum d for j in range(l):
                t=heapq.heappop(d)
                if t<0:
                    res-=t
                else:
                    break
             j range(l) range l t=heapq.heappop(d) t heapq.heappop(d) heapq.heappop heapq heappop d if t<0:
                    res-=t
                else:
                    break
             t<0 t 0 res-=t res t break if s<res:
                s=res s<res s res s=res s res for l in range(n+1):
        for i in range(n-l+1):
            d=v[:i]
            d.extend(v[(l+i):])
            heap=heapq.heapify(d)
            res=sum(d)
            for j in range(k-(n-l)):
                if not d:
                    break
                t=heapq.heappop(d)
                if t<0:
                    res-=t
                else:
                    break
            if s<res:
                s=res

         l range(n+1) range n+1 n 1 for i in range(n-l+1):
            d=v[:i]
            d.extend(v[(l+i):])
            heap=heapq.heapify(d)
            res=sum(d)
            for j in range(k-(n-l)):
                if not d:
                    break
                t=heapq.heappop(d)
                if t<0:
                    res-=t
                else:
                    break
            if s<res:
                s=res

         i range(n-l+1) range n-l+1 n-l n l 1 d=v[:i] d v[:i] v :i i d.extend(v[(l+i):]) d.extend d extend v[(l+i):] v (l+i): l+i l i heap=heapq.heapify(d) heap heapq.heapify(d) heapq.heapify heapq heapify d res=sum(d) res sum(d) sum d for j in range(k-(n-l)):
                if not d:
                    break
                t=heapq.heappop(d)
                if t<0:
                    res-=t
                else:
                    break
             j range(k-(n-l)) range k-(n-l) k n-l n l if not d:
                    break
                 not d d break t=heapq.heappop(d) t heapq.heappop(d) heapq.heappop heapq heappop d if t<0:
                    res-=t
                else:
                    break
             t<0 t 0 res-=t res t break if s<res:
                s=res

         s<res s res s=res s res if s<0:
    print(0)
else:
    print(s)
         s<0 s 0 print(0) print 0 print(s) print s res-=t t res d=v[:i] v[:i] d s=res res s res=sum(d) sum(d) res s=res res s k=map(int,input().split()) map(int,input().split()) k res-=t t res d=v[:i] v[:i] d heap=heapq.heapify(d) heapq.heapify(d) heap t=heapq.heappop(d) heapq.heappop(d) t res=sum(d) sum(d) res t=heapq.heappop(d) heapq.heappop(d) t s=-10**7-1 -10**7-1 s heap=heapq.heapify(d) heapq.heapify(d) heap v=list(map(int,input().split())) list(map(int,input().split())) v n,k=map(int,input().split()) map(int,input().split()) n
import heapq

n,k=map(int,input().split())
v=list(map(int,input().split()))
s=-10**7-1

if n>k:
    for l in range(k//2+1):
        for i in range(k+1-l):
            d=v[:i]
            d.extend(v[(n-k+l+i):])
            heap=heapq.heapify(d)
            res=sum(d)
            for j in range(l):
                t=heapq.heappop(d)
                if t<0:
                    res-=t
                else:
                    break
            if s<res:
                s=res
else:
    for l in range(n+1):
        for i in range(n-l+1):
            d=v[:i]
            d.extend(v[(l+i):])
            heap=heapq.heapify(d)
            res=sum(d)
            for j in range(k-(n-l)):
                if not d:
                    break
                t=heapq.heappop(d)
                if t<0:
                    res-=t
                else:
                    break
            if s<res:
                s=res

        
if s<0:
    print(0)
else:
    print(s)
        
