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


ans = 0

for i in range(1, k + 1):
    if i <= n:
        for j in range(i + 1):
            l = v[:j] + v[n - i + j:]
            l.sort()
            kari = sum(l)
            for x in range(min(k - i, i)):
                if l[x] >= 0:
                    break
                kari -= l[x]
            ans = max(ans, kari)

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 i in range(1, k + 1):
    if i <= n:
        for j in range(i + 1):
            l = v[:j] + v[n - i + j:]
            l.sort()
            kari = sum(l)
            for x in range(min(k - i, i)):
                if l[x] >= 0:
                    break
                kari -= l[x]
            ans = max(ans, kari) i range(1, k + 1) range 1 k + 1 k 1 if i <= n:
        for j in range(i + 1):
            l = v[:j] + v[n - i + j:]
            l.sort()
            kari = sum(l)
            for x in range(min(k - i, i)):
                if l[x] >= 0:
                    break
                kari -= l[x]
            ans = max(ans, kari) i <= n i n for j in range(i + 1):
            l = v[:j] + v[n - i + j:]
            l.sort()
            kari = sum(l)
            for x in range(min(k - i, i)):
                if l[x] >= 0:
                    break
                kari -= l[x]
            ans = max(ans, kari) j range(i + 1) range i + 1 i 1 l = v[:j] + v[n - i + j:] l v[:j] + v[n - i + j:] v[:j] v :j j v[n - i + j:] v n - i + j: n - i + j n - i n i j l.sort() l.sort l sort kari = sum(l) kari sum(l) sum l for x in range(min(k - i, i)):
                if l[x] >= 0:
                    break
                kari -= l[x]
             x range(min(k - i, i)) range min(k - i, i) min k - i k i i if l[x] >= 0:
                    break
                 l[x] >= 0 l[x] l x 0 break kari -= l[x] kari l[x] l x ans = max(ans, kari) ans max(ans, kari) max ans kari print(ans) print ans k = map(int, input().split()) map(int, input().split()) k n,k = map(int, input().split()) map(int, input().split()) n ans = max(ans, kari) max(ans, kari) ans kari = sum(l) sum(l) kari ans = 0 0 ans l = v[:j] + v[n - i + j:] v[:j] + v[n - i + j:] l kari -= l[x] l[x] kari v = list(map(int, input().split())) list(map(int, input().split())) v
n,k = map(int, input().split())
v = list(map(int, input().split()))


ans = 0

for i in range(1, k + 1):
    if i <= n:
        for j in range(i + 1):
            l = v[:j] + v[n - i + j:]
            l.sort()
            kari = sum(l)
            for x in range(min(k - i, i)):
                if l[x] >= 0:
                    break
                kari -= l[x]
            ans = max(ans, kari)

print(ans)