# AtCoder
N, K = map(int, input().split())
V = list(map(int, input().split()))
ans = 0
for l in range(K+1):
    for r in range(K-l+1):
        if l+r > N:
            break
        d = K-(l+r)

        j = V[:l]+V[N-r:]
        j.sort()

        for i in range(d):
            if not j:
                break
            elif j[0] >= 0:
                break
            j.pop(0)

        ans = max(ans, sum(j))
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(K+1):
    for r in range(K-l+1):
        if l+r > N:
            break
        d = K-(l+r)

        j = V[:l]+V[N-r:]
        j.sort()

        for i in range(d):
            if not j:
                break
            elif j[0] >= 0:
                break
            j.pop(0)

        ans = max(ans, sum(j)) l range(K+1) range K+1 K 1 for r in range(K-l+1):
        if l+r > N:
            break
        d = K-(l+r)

        j = V[:l]+V[N-r:]
        j.sort()

        for i in range(d):
            if not j:
                break
            elif j[0] >= 0:
                break
            j.pop(0)

        ans = max(ans, sum(j)) r range(K-l+1) range K-l+1 K-l K l 1 if l+r > N:
            break
         l+r > N l+r l r N break d = K-(l+r) d K-(l+r) K l+r l r j = V[:l]+V[N-r:] j V[:l]+V[N-r:] V[:l] V :l l V[N-r:] V N-r: N-r N r j.sort() j.sort j sort for i in range(d):
            if not j:
                break
            elif j[0] >= 0:
                break
            j.pop(0)

         i range(d) range d if not j:
                break
            elif j[0] >= 0:
                break
             not j j break elif j[0] >= 0:
                break
             j[0] >= 0 j[0] j 0 0 break j.pop(0) j.pop j pop 0 ans = max(ans, sum(j)) ans max(ans, sum(j)) max ans sum(j) sum j print(ans) print ans d = K-(l+r) K-(l+r) d N, K = map(int, input().split()) map(int, input().split()) N j = V[:l]+V[N-r:] V[:l]+V[N-r:] j V = list(map(int, input().split())) list(map(int, input().split())) V ans = 0 0 ans ans = max(ans, sum(j)) max(ans, sum(j)) ans K = map(int, input().split()) map(int, input().split()) K
# AtCoder
N, K = map(int, input().split())
V = list(map(int, input().split()))
ans = 0
for l in range(K+1):
    for r in range(K-l+1):
        if l+r > N:
            break
        d = K-(l+r)

        j = V[:l]+V[N-r:]
        j.sort()

        for i in range(d):
            if not j:
                break
            elif j[0] >= 0:
                break
            j.pop(0)

        ans = max(ans, sum(j))
print(ans)
