N, K = map(int, input().split())
V = list(map(int, input().split()))
ans = 0

#左からl個、右からr個取り出す
for l in range(K + 1):
    for r in range(K - l + 1):
        if l + r > N: continue
        d = K - l - r
        now = 0
        having = []
        for i in range(l):
            now += V[i]
            having.append(V[i])
        for i in range(N-r, N):
            now += V[i]
            having.append(V[i])

        having.sort()
        #d回まで持っている宝石(価値がマイナス)を戻す
        for i in range(d):
            if i >= len(having): break
            if having[i] >= 0: break
            now -= having[i]
        ans = max(ans, now)

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: continue
        d = K - l - r
        now = 0
        having = []
        for i in range(l):
            now += V[i]
            having.append(V[i])
        for i in range(N-r, N):
            now += V[i]
            having.append(V[i])

        having.sort()
        #d回まで持っている宝石(価値がマイナス)を戻す
        for i in range(d):
            if i >= len(having): break
            if having[i] >= 0: break
            now -= having[i]
        ans = max(ans, now) l range(K + 1) range K + 1 K 1 for r in range(K - l + 1):
        if l + r > N: continue
        d = K - l - r
        now = 0
        having = []
        for i in range(l):
            now += V[i]
            having.append(V[i])
        for i in range(N-r, N):
            now += V[i]
            having.append(V[i])

        having.sort()
        #d回まで持っている宝石(価値がマイナス)を戻す
        for i in range(d):
            if i >= len(having): break
            if having[i] >= 0: break
            now -= having[i]
        ans = max(ans, now) r range(K - l + 1) range K - l + 1 K - l K l 1 if l + r > N: continue
         l + r > N l + r l r N d = K - l - r d K - l - r K - l K l r now = 0 now 0 having = [] having [] for i in range(l):
            now += V[i]
            having.append(V[i])
         i range(l) range l now += V[i] now V[i] V i having.append(V[i]) having.append having append V[i] V i for i in range(N-r, N):
            now += V[i]
            having.append(V[i])

         i range(N-r, N) range N-r N r N now += V[i] now V[i] V i having.append(V[i]) having.append having append V[i] V i having.sort() having.sort having sort for i in range(d):
            if i >= len(having): break
            if having[i] >= 0: break
            now -= having[i]
         i range(d) range d if i >= len(having): break
             i >= len(having) i len(having) len having if having[i] >= 0: break
             having[i] >= 0 having[i] having i 0 now -= having[i] now having[i] having i ans = max(ans, now) ans max(ans, now) max ans now print(ans) print ans K = map(int, input().split()) map(int, input().split()) K now -= having[i] having[i] now N, K = map(int, input().split()) map(int, input().split()) N having = [] [] having now = 0 0 now ans = max(ans, now) max(ans, now) ans ans = 0 0 ans now += V[i] V[i] now now += V[i] V[i] now V = list(map(int, input().split())) list(map(int, input().split())) V d = K - l - r K - l - r d
N, K = map(int, input().split())
V = list(map(int, input().split()))
ans = 0

#左からl個、右からr個取り出す
for l in range(K + 1):
    for r in range(K - l + 1):
        if l + r > N: continue
        d = K - l - r
        now = 0
        having = []
        for i in range(l):
            now += V[i]
            having.append(V[i])
        for i in range(N-r, N):
            now += V[i]
            having.append(V[i])

        having.sort()
        #d回まで持っている宝石(価値がマイナス)を戻す
        for i in range(d):
            if i >= len(having): break
            if having[i] >= 0: break
            now -= having[i]
        ans = max(ans, now)

print(ans)
