n,k = map(int,input().split())
v = list(map(int,input().split()))
ans = 0
for i in range(min(n+1,k+1)):
    for j in range(min(n+1-i,k+1-i)):
        g = []
        x = 0
        while x < i:
            g.append(v[x])
            x += 1
        y = 0
        z = -1
        while y < j:
            g.append(v[z])
            y += 1
            z -= 1
        g.sort()
        x = k - i - j
        for z in range(min(len(g),x)):
            if g[z] < 0:
                g[z] = 0
            else:
                break
        ans = max(ans,sum(g))
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(min(n+1,k+1)):
    for j in range(min(n+1-i,k+1-i)):
        g = []
        x = 0
        while x < i:
            g.append(v[x])
            x += 1
        y = 0
        z = -1
        while y < j:
            g.append(v[z])
            y += 1
            z -= 1
        g.sort()
        x = k - i - j
        for z in range(min(len(g),x)):
            if g[z] < 0:
                g[z] = 0
            else:
                break
        ans = max(ans,sum(g)) i range(min(n+1,k+1)) range min(n+1,k+1) min n+1 n 1 k+1 k 1 for j in range(min(n+1-i,k+1-i)):
        g = []
        x = 0
        while x < i:
            g.append(v[x])
            x += 1
        y = 0
        z = -1
        while y < j:
            g.append(v[z])
            y += 1
            z -= 1
        g.sort()
        x = k - i - j
        for z in range(min(len(g),x)):
            if g[z] < 0:
                g[z] = 0
            else:
                break
        ans = max(ans,sum(g)) j range(min(n+1-i,k+1-i)) range min(n+1-i,k+1-i) min n+1-i n+1 n 1 i k+1-i k+1 k 1 i g = [] g [] x = 0 x 0 while x < i:
            g.append(v[x])
            x += 1
         x < i x i g.append(v[x]) g.append g append v[x] v x x += 1 x 1 y = 0 y 0 z = -1 z -1 while y < j:
            g.append(v[z])
            y += 1
            z -= 1
         y < j y j g.append(v[z]) g.append g append v[z] v z y += 1 y 1 z -= 1 z 1 g.sort() g.sort g sort x = k - i - j x k - i - j k - i k i j for z in range(min(len(g),x)):
            if g[z] < 0:
                g[z] = 0
            else:
                break
         z range(min(len(g),x)) range min(len(g),x) min len(g) len g x if g[z] < 0:
                g[z] = 0
            else:
                break
         g[z] < 0 g[z] g z 0 g[z] = 0 g[z] g z 0 break ans = max(ans,sum(g)) ans max(ans,sum(g)) max ans sum(g) sum g print(ans) print ans k = map(int,input().split()) map(int,input().split()) k z = -1 -1 z ans = 0 0 ans y += 1 1 y ans = max(ans,sum(g)) max(ans,sum(g)) ans y = 0 0 y x = k - i - j k - i - j x x += 1 1 x g = [] [] g n,k = map(int,input().split()) map(int,input().split()) n x = 0 0 x v = list(map(int,input().split())) list(map(int,input().split())) v z -= 1 1 z
n,k = map(int,input().split())
v = list(map(int,input().split()))
ans = 0
for i in range(min(n+1,k+1)):
    for j in range(min(n+1-i,k+1-i)):
        g = []
        x = 0
        while x < i:
            g.append(v[x])
            x += 1
        y = 0
        z = -1
        while y < j:
            g.append(v[z])
            y += 1
            z -= 1
        g.sort()
        x = k - i - j
        for z in range(min(len(g),x)):
            if g[z] < 0:
                g[z] = 0
            else:
                break
        ans = max(ans,sum(g))
print(ans)