N,K = map(int,input().split())
A = list(map(int,input().split()))
m = min(N,K)
M = 0 
for i in range(m+1):
    for j in range(m-i+1):
        v=A[:i]+A[N-j:]
        v.sort()
        v=v[::-1]
        h=K-len(v)
        while h >0 and v:
            if v[-1] > 0:
                break
            else:
                v.pop()
                h-=1
        M=max(M,sum(v))
print(M) N,K = map(int,input().split()) N map(int,input().split()) map int input().split() ().split () input split K A = list(map(int,input().split())) A list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split m = min(N,K) m min(N,K) min N K M = 0 M 0 for i in range(m+1):
    for j in range(m-i+1):
        v=A[:i]+A[N-j:]
        v.sort()
        v=v[::-1]
        h=K-len(v)
        while h >0 and v:
            if v[-1] > 0:
                break
            else:
                v.pop()
                h-=1
        M=max(M,sum(v)) i range(m+1) range m+1 m 1 for j in range(m-i+1):
        v=A[:i]+A[N-j:]
        v.sort()
        v=v[::-1]
        h=K-len(v)
        while h >0 and v:
            if v[-1] > 0:
                break
            else:
                v.pop()
                h-=1
        M=max(M,sum(v)) j range(m-i+1) range m-i+1 m-i m i 1 v=A[:i]+A[N-j:] v A[:i]+A[N-j:] A[:i] A :i i A[N-j:] A N-j: N-j N j v.sort() v.sort v sort v=v[::-1] v v[::-1] v ::-1 -1 h=K-len(v) h K-len(v) K len(v) len v while h >0 and v:
            if v[-1] > 0:
                break
            else:
                v.pop()
                h-=1
         h >0 and v h >0 h 0 v if v[-1] > 0:
                break
            else:
                v.pop()
                h-=1
         v[-1] > 0 v[-1] v -1 0 break v.pop() v.pop v pop h-=1 h 1 M=max(M,sum(v)) M max(M,sum(v)) max M sum(v) sum v print(M) print M m = min(N,K) min(N,K) m h-=1 1 h N,K = map(int,input().split()) map(int,input().split()) N K = map(int,input().split()) map(int,input().split()) K v=A[:i]+A[N-j:] A[:i]+A[N-j:] v M=max(M,sum(v)) max(M,sum(v)) M M = 0 0 M A = list(map(int,input().split())) list(map(int,input().split())) A v=v[::-1] v[::-1] v h=K-len(v) K-len(v) h
N,K = map(int,input().split())
A = list(map(int,input().split()))
m = min(N,K)
M = 0 
for i in range(m+1):
    for j in range(m-i+1):
        v=A[:i]+A[N-j:]
        v.sort()
        v=v[::-1]
        h=K-len(v)
        while h >0 and v:
            if v[-1] > 0:
                break
            else:
                v.pop()
                h-=1
        M=max(M,sum(v))
print(M)