n,k = map(int,input().split())
V = list(map(int,input().split()))
Vi = V[::-1]
t = min(n,k)
ans = 0
for i in range(1,t+1):#選ぶ個数
    for a in range(0,i+1):
        b = i-a
        houseki = V[0:a] + Vi[0:b]
        houseki.sort()
        tmp=sum(houseki)
        for idx,val in enumerate(houseki):
            if idx==k-i:break
            if val<0:tmp-=val
        ans = max(ans,tmp)
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 Vi = V[::-1] Vi V[::-1] V ::-1 -1 t = min(n,k) t min(n,k) min n k ans = 0 ans 0 for i in range(1,t+1):#選ぶ個数
    for a in range(0,i+1):
        b = i-a
        houseki = V[0:a] + Vi[0:b]
        houseki.sort()
        tmp=sum(houseki)
        for idx,val in enumerate(houseki):
            if idx==k-i:break
            if val<0:tmp-=val
        ans = max(ans,tmp) i range(1,t+1) range 1 t+1 t 1 for a in range(0,i+1):
        b = i-a
        houseki = V[0:a] + Vi[0:b]
        houseki.sort()
        tmp=sum(houseki)
        for idx,val in enumerate(houseki):
            if idx==k-i:break
            if val<0:tmp-=val
        ans = max(ans,tmp) a range(0,i+1) range 0 i+1 i 1 b = i-a b i-a i a houseki = V[0:a] + Vi[0:b] houseki V[0:a] + Vi[0:b] V[0:a] V 0:a 0 a Vi[0:b] Vi 0:b 0 b houseki.sort() houseki.sort houseki sort tmp=sum(houseki) tmp sum(houseki) sum houseki for idx,val in enumerate(houseki):
            if idx==k-i:break
            if val<0:tmp-=val
         idx val enumerate(houseki) enumerate houseki if idx==k-i:break
             idx==k-i idx k-i k i if val<0:tmp-=val
         val<0 val 0 ans = max(ans,tmp) ans max(ans,tmp) max ans tmp print(ans) print ans tmp=sum(houseki) sum(houseki) tmp Vi = V[::-1] V[::-1] Vi ans = 0 0 ans n,k = map(int,input().split()) map(int,input().split()) n V = list(map(int,input().split())) list(map(int,input().split())) V k = map(int,input().split()) map(int,input().split()) k houseki = V[0:a] + Vi[0:b] V[0:a] + Vi[0:b] houseki ans = max(ans,tmp) max(ans,tmp) ans t = min(n,k) min(n,k) t b = i-a i-a b
n,k = map(int,input().split())
V = list(map(int,input().split()))
Vi = V[::-1]
t = min(n,k)
ans = 0
for i in range(1,t+1):#選ぶ個数
    for a in range(0,i+1):
        b = i-a
        houseki = V[0:a] + Vi[0:b]
        houseki.sort()
        tmp=sum(houseki)
        for idx,val in enumerate(houseki):
            if idx==k-i:break
            if val<0:tmp-=val
        ans = max(ans,tmp)
print(ans)
