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):
        if i+j>N:
            continue
        
        l = []
        
        for k in range(i):
            l.append(V[k])
        
        for k in range(j):
            l.append(V[N-1-k])
        
        if len(l)>K:
            continue
        
        l.sort()
        cnt = K-len(l)
        now = 0
        
        while cnt>0 and now<len(l) and l[now]<0:
            cnt -= 1
            now += 1
        
        ans = max(ans, sum(l[now:]))

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):
        if i+j>N:
            continue
        
        l = []
        
        for k in range(i):
            l.append(V[k])
        
        for k in range(j):
            l.append(V[N-1-k])
        
        if len(l)>K:
            continue
        
        l.sort()
        cnt = K-len(l)
        now = 0
        
        while cnt>0 and now<len(l) and l[now]<0:
            cnt -= 1
            now += 1
        
        ans = max(ans, sum(l[now:])) i range(N+1) range N+1 N 1 for j in range(N+1):
        if i+j>N:
            continue
        
        l = []
        
        for k in range(i):
            l.append(V[k])
        
        for k in range(j):
            l.append(V[N-1-k])
        
        if len(l)>K:
            continue
        
        l.sort()
        cnt = K-len(l)
        now = 0
        
        while cnt>0 and now<len(l) and l[now]<0:
            cnt -= 1
            now += 1
        
        ans = max(ans, sum(l[now:])) j range(N+1) range N+1 N 1 if i+j>N:
            continue
        
         i+j>N i+j i j N continue l = [] l [] for k in range(i):
            l.append(V[k])
        
         k range(i) range i l.append(V[k]) l.append l append V[k] V k for k in range(j):
            l.append(V[N-1-k])
        
         k range(j) range j l.append(V[N-1-k]) l.append l append V[N-1-k] V N-1-k N-1 N 1 k if len(l)>K:
            continue
        
         len(l)>K len(l) len l K continue l.sort() l.sort l sort cnt = K-len(l) cnt K-len(l) K len(l) len l now = 0 now 0 while cnt>0 and now<len(l) and l[now]<0:
            cnt -= 1
            now += 1
        
         cnt>0 and now<len(l) and l[now]<0 cnt>0 and now<len(l) cnt>0 cnt 0 now<len(l) now len(l) len l l[now]<0 l[now] l now 0 cnt -= 1 cnt 1 now += 1 now 1 ans = max(ans, sum(l[now:])) ans max(ans, sum(l[now:])) max ans sum(l[now:]) sum l[now:] l now: now print(ans) print ans cnt = K-len(l) K-len(l) cnt now = 0 0 now ans = 0 0 ans l = [] [] l N, K = map(int, input().split()) map(int, input().split()) N cnt -= 1 1 cnt now += 1 1 now V = list(map(int, input().split())) list(map(int, input().split())) V K = map(int, input().split()) map(int, input().split()) K ans = max(ans, sum(l[now:])) max(ans, sum(l[now:])) ans
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):
        if i+j>N:
            continue
        
        l = []
        
        for k in range(i):
            l.append(V[k])
        
        for k in range(j):
            l.append(V[N-1-k])
        
        if len(l)>K:
            continue
        
        l.sort()
        cnt = K-len(l)
        now = 0
        
        while cnt>0 and now<len(l) and l[now]<0:
            cnt -= 1
            now += 1
        
        ans = max(ans, sum(l[now:]))

print(ans)