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

ans = -1

for l in range(N+1):
    for r in range(N+1):
        tmp = V[:l] + V[N-r:]
        if l+r > N:
            break
        res = K - (l+r)
        if res < 0:
            break
        tmp.sort()
        for i in range(min(res,len(tmp))):
            if tmp[0] < 0:
                tmp.pop(0)
            else:
                break
        ans = max(ans,sum(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 = -1 ans -1 for l in range(N+1):
    for r in range(N+1):
        tmp = V[:l] + V[N-r:]
        if l+r > N:
            break
        res = K - (l+r)
        if res < 0:
            break
        tmp.sort()
        for i in range(min(res,len(tmp))):
            if tmp[0] < 0:
                tmp.pop(0)
            else:
                break
        ans = max(ans,sum(tmp))
             l range(N+1) range N+1 N 1 for r in range(N+1):
        tmp = V[:l] + V[N-r:]
        if l+r > N:
            break
        res = K - (l+r)
        if res < 0:
            break
        tmp.sort()
        for i in range(min(res,len(tmp))):
            if tmp[0] < 0:
                tmp.pop(0)
            else:
                break
        ans = max(ans,sum(tmp))
             r range(N+1) range N+1 N 1 tmp = V[:l] + V[N-r:] tmp V[:l] + V[N-r:] V[:l] V :l l V[N-r:] V N-r: N-r N r if l+r > N:
            break
         l+r > N l+r l r N break res = K - (l+r) res K - (l+r) K l+r l r if res < 0:
            break
         res < 0 res 0 break tmp.sort() tmp.sort tmp sort for i in range(min(res,len(tmp))):
            if tmp[0] < 0:
                tmp.pop(0)
            else:
                break
         i range(min(res,len(tmp))) range min(res,len(tmp)) min res len(tmp) len tmp if tmp[0] < 0:
                tmp.pop(0)
            else:
                break
         tmp[0] < 0 tmp[0] tmp 0 0 tmp.pop(0) tmp.pop tmp pop 0 break ans = max(ans,sum(tmp)) ans max(ans,sum(tmp)) max ans sum(tmp) sum tmp print(ans) print ans K = map(int,input().split()) map(int,input().split()) K V = list(map(int,input().split())) list(map(int,input().split())) V tmp = V[:l] + V[N-r:] V[:l] + V[N-r:] tmp res = K - (l+r) K - (l+r) res ans = max(ans,sum(tmp)) max(ans,sum(tmp)) ans N,K = map(int,input().split()) map(int,input().split()) N ans = -1 -1 ans
N,K = map(int,input().split())
V = list(map(int,input().split()))

ans = -1

for l in range(N+1):
    for r in range(N+1):
        tmp = V[:l] + V[N-r:]
        if l+r > N:
            break
        res = K - (l+r)
        if res < 0:
            break
        tmp.sort()
        for i in range(min(res,len(tmp))):
            if tmp[0] < 0:
                tmp.pop(0)
            else:
                break
        ans = max(ans,sum(tmp))
            
print(ans)