n,k = map(int,input().split())
v = list(map(int,input().split()))
ans = 0
for a in range(min(n,k)+1):
    for b in range(min(n,k)-a+1):
        c = v[:a] + v[n-b:]
        c = sorted(c)
        for i in range(k-a-b):
            if len(c) == 0:
                break
            if c[0] < 0:
                c = c[1:]
            else:
                break
        ans = max(ans,sum(c))
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 a in range(min(n,k)+1):
    for b in range(min(n,k)-a+1):
        c = v[:a] + v[n-b:]
        c = sorted(c)
        for i in range(k-a-b):
            if len(c) == 0:
                break
            if c[0] < 0:
                c = c[1:]
            else:
                break
        ans = max(ans,sum(c)) a range(min(n,k)+1) range min(n,k)+1 min(n,k) min n k 1 for b in range(min(n,k)-a+1):
        c = v[:a] + v[n-b:]
        c = sorted(c)
        for i in range(k-a-b):
            if len(c) == 0:
                break
            if c[0] < 0:
                c = c[1:]
            else:
                break
        ans = max(ans,sum(c)) b range(min(n,k)-a+1) range min(n,k)-a+1 min(n,k)-a min(n,k) min n k a 1 c = v[:a] + v[n-b:] c v[:a] + v[n-b:] v[:a] v :a a v[n-b:] v n-b: n-b n b c = sorted(c) c sorted(c) sorted c for i in range(k-a-b):
            if len(c) == 0:
                break
            if c[0] < 0:
                c = c[1:]
            else:
                break
         i range(k-a-b) range k-a-b k-a k a b if len(c) == 0:
                break
             len(c) == 0 len(c) len c 0 break if c[0] < 0:
                c = c[1:]
            else:
                break
         c[0] < 0 c[0] c 0 0 c = c[1:] c c[1:] c 1: 1 break ans = max(ans,sum(c)) ans max(ans,sum(c)) max ans sum(c) sum c print(ans) print ans c = sorted(c) sorted(c) c c = c[1:] c[1:] c c = v[:a] + v[n-b:] v[:a] + v[n-b:] c ans = 0 0 ans v = list(map(int,input().split())) list(map(int,input().split())) v n,k = map(int,input().split()) map(int,input().split()) n k = map(int,input().split()) map(int,input().split()) k ans = max(ans,sum(c)) max(ans,sum(c)) ans
n,k = map(int,input().split())
v = list(map(int,input().split()))
ans = 0
for a in range(min(n,k)+1):
    for b in range(min(n,k)-a+1):
        c = v[:a] + v[n-b:]
        c = sorted(c)
        for i in range(k-a-b):
            if len(c) == 0:
                break
            if c[0] < 0:
                c = c[1:]
            else:
                break
        ans = max(ans,sum(c))
print(ans)
