import sys

N, K = map(int, sys.stdin.readline().strip().split())
V = list(map(int, sys.stdin.readline().strip().split()))

ans=0
act = min(N, K)
for i in range(act + 1): # 左
    for j in range(N - act + i, N+1): # 右
        count = V[0:i] + V[j:N]
        count.sort()
        ans = max(ans, sum(count))
        for x in range(1, K - len(count) + 1): # 正負関係なく小さいものを捨てる 
            # print(sum(count[x:]))
            ans = max(ans, sum(count[x:]))
print(ans) import sys sys N, K = map(int, sys.stdin.readline().strip().split()) N map(int, sys.stdin.readline().strip().split()) map int sys.stdin.readline().strip().split() sys.stdin.readline().strip().split sys.stdin.readline().strip() sys.stdin.readline().strip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline strip split K V = list(map(int, sys.stdin.readline().strip().split())) V list(map(int, sys.stdin.readline().strip().split())) list map(int, sys.stdin.readline().strip().split()) map int sys.stdin.readline().strip().split() sys.stdin.readline().strip().split sys.stdin.readline().strip() sys.stdin.readline().strip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline strip split ans=0 ans 0 act = min(N, K) act min(N, K) min N K for i in range(act + 1): # 左
    for j in range(N - act + i, N+1): # 右
        count = V[0:i] + V[j:N]
        count.sort()
        ans = max(ans, sum(count))
        for x in range(1, K - len(count) + 1): # 正負関係なく小さいものを捨てる 
            # print(sum(count[x:]))
            ans = max(ans, sum(count[x:])) i range(act + 1) range act + 1 act 1 for j in range(N - act + i, N+1): # 右
        count = V[0:i] + V[j:N]
        count.sort()
        ans = max(ans, sum(count))
        for x in range(1, K - len(count) + 1): # 正負関係なく小さいものを捨てる 
            # print(sum(count[x:]))
            ans = max(ans, sum(count[x:])) j range(N - act + i, N+1) range N - act + i N - act N act i N+1 N 1 count = V[0:i] + V[j:N] count V[0:i] + V[j:N] V[0:i] V 0:i 0 i V[j:N] V j:N j N count.sort() count.sort count sort ans = max(ans, sum(count)) ans max(ans, sum(count)) max ans sum(count) sum count for x in range(1, K - len(count) + 1): # 正負関係なく小さいものを捨てる 
            # print(sum(count[x:]))
            ans = max(ans, sum(count[x:])) x range(1, K - len(count) + 1) range 1 K - len(count) + 1 K - len(count) K len(count) len count 1 ans = max(ans, sum(count[x:])) ans max(ans, sum(count[x:])) max ans sum(count[x:]) sum count[x:] count x: x print(ans) print ans act = min(N, K) min(N, K) act count = V[0:i] + V[j:N] V[0:i] + V[j:N] count ans = max(ans, sum(count)) max(ans, sum(count)) ans V = list(map(int, sys.stdin.readline().strip().split())) list(map(int, sys.stdin.readline().strip().split())) V ans = max(ans, sum(count[x:])) max(ans, sum(count[x:])) ans K = map(int, sys.stdin.readline().strip().split()) map(int, sys.stdin.readline().strip().split()) K ans=0 0 ans N, K = map(int, sys.stdin.readline().strip().split()) map(int, sys.stdin.readline().strip().split()) N
import sys

N, K = map(int, sys.stdin.readline().strip().split())
V = list(map(int, sys.stdin.readline().strip().split()))

ans=0
act = min(N, K)
for i in range(act + 1): # 左
    for j in range(N - act + i, N+1): # 右
        count = V[0:i] + V[j:N]
        count.sort()
        ans = max(ans, sum(count))
        for x in range(1, K - len(count) + 1): # 正負関係なく小さいものを捨てる 
            # print(sum(count[x:]))
            ans = max(ans, sum(count[x:]))
print(ans)