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

ans = 0
for l in range(N+1):
    for r in range(N+1):
        if l+r > N or l+r > K: break
        arr = V[:l]
        if r: arr += V[-r:]
        arr.sort()
        rem = K - l - r
        tmp = 0
        for a in arr:
            if a < 0 and rem:
                rem -= 1
            else:
                tmp += a
        ans = max(ans, tmp)
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(N+1):
    for r in range(N+1):
        if l+r > N or l+r > K: break
        arr = V[:l]
        if r: arr += V[-r:]
        arr.sort()
        rem = K - l - r
        tmp = 0
        for a in arr:
            if a < 0 and rem:
                rem -= 1
            else:
                tmp += a
        ans = max(ans, tmp) l range(N+1) range N+1 N 1 for r in range(N+1):
        if l+r > N or l+r > K: break
        arr = V[:l]
        if r: arr += V[-r:]
        arr.sort()
        rem = K - l - r
        tmp = 0
        for a in arr:
            if a < 0 and rem:
                rem -= 1
            else:
                tmp += a
        ans = max(ans, tmp) r range(N+1) range N+1 N 1 if l+r > N or l+r > K: break
         l+r > N or l+r > K l+r > N l+r l r N l+r > K l+r l r K arr = V[:l] arr V[:l] V :l l if r: arr += V[-r:]
         r arr.sort() arr.sort arr sort rem = K - l - r rem K - l - r K - l K l r tmp = 0 tmp 0 for a in arr:
            if a < 0 and rem:
                rem -= 1
            else:
                tmp += a
         a arr if a < 0 and rem:
                rem -= 1
            else:
                tmp += a
         a < 0 and rem a < 0 a 0 rem rem -= 1 rem 1 tmp += a tmp a ans = max(ans, tmp) ans max(ans, tmp) max ans tmp print(ans) print ans rem -= 1 1 rem K = map(int,input().split()) map(int,input().split()) K rem = K - l - r K - l - r rem ans = max(ans, tmp) max(ans, tmp) ans N,K = map(int,input().split()) map(int,input().split()) N tmp = 0 0 tmp tmp += a a tmp ans = 0 0 ans V = list(map(int,input().split())) list(map(int,input().split())) V arr = V[:l] V[:l] arr
N,K = map(int,input().split())
V = list(map(int,input().split()))

ans = 0
for l in range(N+1):
    for r in range(N+1):
        if l+r > N or l+r > K: break
        arr = V[:l]
        if r: arr += V[-r:]
        arr.sort()
        rem = K - l - r
        tmp = 0
        for a in arr:
            if a < 0 and rem:
                rem -= 1
            else:
                tmp += a
        ans = max(ans, tmp)
print(ans)