n, k = map(int,input().split())
v = list(map(int,input().split()))

ans = 0

for l in range(n):
    for r in range(n+1)[::-1]:
        if l <= r and 0 <= (l+n-r) <= k: # l+n-r個拾う
            q = v[:l] + v[r:n]
            q.sort(reverse = True)
            
            for i in range(k-(l+n-r)):
                if q == []:
                    break
                if q[-1] < 0:
                    q.pop()
                else:
                    break

            ans = max(ans, sum(q))
        else:
            continue

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 l in range(n):
    for r in range(n+1)[::-1]:
        if l <= r and 0 <= (l+n-r) <= k: # l+n-r個拾う
            q = v[:l] + v[r:n]
            q.sort(reverse = True)
            
            for i in range(k-(l+n-r)):
                if q == []:
                    break
                if q[-1] < 0:
                    q.pop()
                else:
                    break

            ans = max(ans, sum(q))
        else:
            continue l range(n) range n for r in range(n+1)[::-1]:
        if l <= r and 0 <= (l+n-r) <= k: # l+n-r個拾う
            q = v[:l] + v[r:n]
            q.sort(reverse = True)
            
            for i in range(k-(l+n-r)):
                if q == []:
                    break
                if q[-1] < 0:
                    q.pop()
                else:
                    break

            ans = max(ans, sum(q))
        else:
            continue r range(n+1)[::-1] (n+1) range n+1 n 1 ::-1 -1 if l <= r and 0 <= (l+n-r) <= k: # l+n-r個拾う
            q = v[:l] + v[r:n]
            q.sort(reverse = True)
            
            for i in range(k-(l+n-r)):
                if q == []:
                    break
                if q[-1] < 0:
                    q.pop()
                else:
                    break

            ans = max(ans, sum(q))
        else:
            continue l <= r and 0 <= (l+n-r) <= k l <= r l r 0 <= (l+n-r) <= k 0 <= (l+n-r) 0 l+n-r l+n l n r k q = v[:l] + v[r:n] q v[:l] + v[r:n] v[:l] v :l l v[r:n] v r:n r n q.sort(reverse = True) q.sort q sort reverse = True reverse True for i in range(k-(l+n-r)):
                if q == []:
                    break
                if q[-1] < 0:
                    q.pop()
                else:
                    break

             i range(k-(l+n-r)) range k-(l+n-r) k l+n-r l+n l n r if q == []:
                    break
                 q == [] q [] break if q[-1] < 0:
                    q.pop()
                else:
                    break

             q[-1] < 0 q[-1] q -1 0 q.pop() q.pop q pop break ans = max(ans, sum(q)) ans max(ans, sum(q)) max ans sum(q) sum q continue print(ans) print ans n, k = map(int,input().split()) map(int,input().split()) n k = map(int,input().split()) map(int,input().split()) k v = list(map(int,input().split())) list(map(int,input().split())) v ans = max(ans, sum(q)) max(ans, sum(q)) ans q = v[:l] + v[r:n] v[:l] + v[r:n] q ans = 0 0 ans
n, k = map(int,input().split())
v = list(map(int,input().split()))

ans = 0

for l in range(n):
    for r in range(n+1)[::-1]:
        if l <= r and 0 <= (l+n-r) <= k: # l+n-r個拾う
            q = v[:l] + v[r:n]
            q.sort(reverse = True)
            
            for i in range(k-(l+n-r)):
                if q == []:
                    break
                if q[-1] < 0:
                    q.pop()
                else:
                    break

            ans = max(ans, sum(q))
        else:
            continue

print(ans)