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

ans = []
# きっちりK回しなくていいみたい
for left in range(N + 1):
    for right in range(N + 1):
        if left + right > N:
            break

        li = V[:left] + V[N - right :]
        li = sorted(li)

        d = K - left - right
        if d < 0:
            break

        c = sum(li)
        for i in range(min(d, len(li))):
            if li[i] < 0:
                c -= li[i]
            else:
                break

        ans.append(c)

print(max(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 = [] ans [] for left in range(N + 1):
    for right in range(N + 1):
        if left + right > N:
            break

        li = V[:left] + V[N - right :]
        li = sorted(li)

        d = K - left - right
        if d < 0:
            break

        c = sum(li)
        for i in range(min(d, len(li))):
            if li[i] < 0:
                c -= li[i]
            else:
                break

        ans.append(c) left range(N + 1) range N + 1 N 1 for right in range(N + 1):
        if left + right > N:
            break

        li = V[:left] + V[N - right :]
        li = sorted(li)

        d = K - left - right
        if d < 0:
            break

        c = sum(li)
        for i in range(min(d, len(li))):
            if li[i] < 0:
                c -= li[i]
            else:
                break

        ans.append(c) right range(N + 1) range N + 1 N 1 if left + right > N:
            break

         left + right > N left + right left right N break li = V[:left] + V[N - right :] li V[:left] + V[N - right :] V[:left] V :left left V[N - right :] V N - right : N - right N right li = sorted(li) li sorted(li) sorted li d = K - left - right d K - left - right K - left K left right if d < 0:
            break

         d < 0 d 0 break c = sum(li) c sum(li) sum li for i in range(min(d, len(li))):
            if li[i] < 0:
                c -= li[i]
            else:
                break

         i range(min(d, len(li))) range min(d, len(li)) min d len(li) len li if li[i] < 0:
                c -= li[i]
            else:
                break

         li[i] < 0 li[i] li i 0 c -= li[i] c li[i] li i break ans.append(c) ans.append ans append c print(max(ans)) print max(ans) max ans N, K = map(int, input().split()) map(int, input().split()) N li = V[:left] + V[N - right :] V[:left] + V[N - right :] li d = K - left - right K - left - right d ans = [] [] ans K = map(int, input().split()) map(int, input().split()) K c = sum(li) sum(li) c li = sorted(li) sorted(li) li V = list(map(int, input().split())) list(map(int, input().split())) V c -= li[i] li[i] c
N, K = map(int, input().split())
V = list(map(int, input().split()))

ans = []
# きっちりK回しなくていいみたい
for left in range(N + 1):
    for right in range(N + 1):
        if left + right > N:
            break

        li = V[:left] + V[N - right :]
        li = sorted(li)

        d = K - left - right
        if d < 0:
            break

        c = sum(li)
        for i in range(min(d, len(li))):
            if li[i] < 0:
                c -= li[i]
            else:
                break

        ans.append(c)

print(max(ans))

