n,k = map(int,input().split())
v = list(map(int,input().split()))
ma = 0
kaisu = min(n,k)
for a in range(kaisu+1):
    for b in range(kaisu-a+1):
        push = k-(a+b)
        li = v[:a]+v[n-b:]
        li.sort(reverse=True)
        for c in range(push):
            if li:
                if li[-1] < 0:
                    li.pop()
        ma = max(ma,sum(li))
print(ma) 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 ma = 0 ma 0 kaisu = min(n,k) kaisu min(n,k) min n k for a in range(kaisu+1):
    for b in range(kaisu-a+1):
        push = k-(a+b)
        li = v[:a]+v[n-b:]
        li.sort(reverse=True)
        for c in range(push):
            if li:
                if li[-1] < 0:
                    li.pop()
        ma = max(ma,sum(li)) a range(kaisu+1) range kaisu+1 kaisu 1 for b in range(kaisu-a+1):
        push = k-(a+b)
        li = v[:a]+v[n-b:]
        li.sort(reverse=True)
        for c in range(push):
            if li:
                if li[-1] < 0:
                    li.pop()
        ma = max(ma,sum(li)) b range(kaisu-a+1) range kaisu-a+1 kaisu-a kaisu a 1 push = k-(a+b) push k-(a+b) k a+b a b li = v[:a]+v[n-b:] li v[:a]+v[n-b:] v[:a] v :a a v[n-b:] v n-b: n-b n b li.sort(reverse=True) li.sort li sort reverse=True reverse True for c in range(push):
            if li:
                if li[-1] < 0:
                    li.pop()
         c range(push) range push if li:
                if li[-1] < 0:
                    li.pop()
         li if li[-1] < 0:
                    li.pop()
         li[-1] < 0 li[-1] li -1 0 li.pop() li.pop li pop ma = max(ma,sum(li)) ma max(ma,sum(li)) max ma sum(li) sum li print(ma) print ma n,k = map(int,input().split()) map(int,input().split()) n li = v[:a]+v[n-b:] v[:a]+v[n-b:] li kaisu = min(n,k) min(n,k) kaisu v = list(map(int,input().split())) list(map(int,input().split())) v k = map(int,input().split()) map(int,input().split()) k ma = max(ma,sum(li)) max(ma,sum(li)) ma ma = 0 0 ma push = k-(a+b) k-(a+b) push
n,k = map(int,input().split())
v = list(map(int,input().split()))
ma = 0
kaisu = min(n,k)
for a in range(kaisu+1):
    for b in range(kaisu-a+1):
        push = k-(a+b)
        li = v[:a]+v[n-b:]
        li.sort(reverse=True)
        for c in range(push):
            if li:
                if li[-1] < 0:
                    li.pop()
        ma = max(ma,sum(li))
print(ma)