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