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

ans = -10**7
for i in range(min(N,K)+1):
    for j in range(min(N-i,K-i)+1):
        for k in range(min(i+j,K-i-j)+1):
            T = V[:i+1]
            T.extend(V[N-j+1:])
            T.sort()
            for t in range(k):
                if T[t] < 0:
                    T[t] = 0
                else:
                    break
            ans = max(ans,sum(T))

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 V.insert(0,0) V.insert V insert 0 0 V.append(0) V.append V append 0 ans = -10**7 ans -10**7 -10 7 for i in range(min(N,K)+1):
    for j in range(min(N-i,K-i)+1):
        for k in range(min(i+j,K-i-j)+1):
            T = V[:i+1]
            T.extend(V[N-j+1:])
            T.sort()
            for t in range(k):
                if T[t] < 0:
                    T[t] = 0
                else:
                    break
            ans = max(ans,sum(T)) i range(min(N,K)+1) range min(N,K)+1 min(N,K) min N K 1 for j in range(min(N-i,K-i)+1):
        for k in range(min(i+j,K-i-j)+1):
            T = V[:i+1]
            T.extend(V[N-j+1:])
            T.sort()
            for t in range(k):
                if T[t] < 0:
                    T[t] = 0
                else:
                    break
            ans = max(ans,sum(T)) j range(min(N-i,K-i)+1) range min(N-i,K-i)+1 min(N-i,K-i) min N-i N i K-i K i 1 for k in range(min(i+j,K-i-j)+1):
            T = V[:i+1]
            T.extend(V[N-j+1:])
            T.sort()
            for t in range(k):
                if T[t] < 0:
                    T[t] = 0
                else:
                    break
            ans = max(ans,sum(T)) k range(min(i+j,K-i-j)+1) range min(i+j,K-i-j)+1 min(i+j,K-i-j) min i+j i j K-i-j K-i K i j 1 T = V[:i+1] T V[:i+1] V :i+1 i+1 i 1 T.extend(V[N-j+1:]) T.extend T extend V[N-j+1:] V N-j+1: N-j+1 N-j N j 1 T.sort() T.sort T sort for t in range(k):
                if T[t] < 0:
                    T[t] = 0
                else:
                    break
             t range(k) range k if T[t] < 0:
                    T[t] = 0
                else:
                    break
             T[t] < 0 T[t] T t 0 T[t] = 0 T[t] T t 0 break ans = max(ans,sum(T)) ans max(ans,sum(T)) max ans sum(T) sum T print(ans) print ans K = map(int,input().split()) map(int,input().split()) K ans = -10**7 -10**7 ans N,K = map(int,input().split()) map(int,input().split()) N V = list(map(int,input().split())) list(map(int,input().split())) V T = V[:i+1] V[:i+1] T ans = max(ans,sum(T)) max(ans,sum(T)) ans
N,K = map(int,input().split())
V = list(map(int,input().split()))
V.insert(0,0)
V.append(0)

ans = -10**7
for i in range(min(N,K)+1):
    for j in range(min(N-i,K-i)+1):
        for k in range(min(i+j,K-i-j)+1):
            T = V[:i+1]
            T.extend(V[N-j+1:])
            T.sort()
            for t in range(k):
                if T[t] < 0:
                    T[t] = 0
                else:
                    break
            ans = max(ans,sum(T))

print(ans)