n,k=map(int,input().split())
v=list(map(int,input().split()))
times=min(n,k)
ans=0
for i in range(times+1):
    l=v[:i]
    for j in range(times-i+1):
        r=l+v[n-j:]
        rest=k-i-j
        val=sum(r)
        r=sorted(r)
        if len(r)>0:
            for p in range(min(rest,len(r))):
                if r[p]<0:
                    val-=r[p]
                else:
                    break
        if val>ans:
            ans=val
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 times=min(n,k) times min(n,k) min n k ans=0 ans 0 for i in range(times+1):
    l=v[:i]
    for j in range(times-i+1):
        r=l+v[n-j:]
        rest=k-i-j
        val=sum(r)
        r=sorted(r)
        if len(r)>0:
            for p in range(min(rest,len(r))):
                if r[p]<0:
                    val-=r[p]
                else:
                    break
        if val>ans:
            ans=val i range(times+1) range times+1 times 1 l=v[:i] l v[:i] v :i i for j in range(times-i+1):
        r=l+v[n-j:]
        rest=k-i-j
        val=sum(r)
        r=sorted(r)
        if len(r)>0:
            for p in range(min(rest,len(r))):
                if r[p]<0:
                    val-=r[p]
                else:
                    break
        if val>ans:
            ans=val j range(times-i+1) range times-i+1 times-i times i 1 r=l+v[n-j:] r l+v[n-j:] l v[n-j:] v n-j: n-j n j rest=k-i-j rest k-i-j k-i k i j val=sum(r) val sum(r) sum r r=sorted(r) r sorted(r) sorted r if len(r)>0:
            for p in range(min(rest,len(r))):
                if r[p]<0:
                    val-=r[p]
                else:
                    break
         len(r)>0 len(r) len r 0 for p in range(min(rest,len(r))):
                if r[p]<0:
                    val-=r[p]
                else:
                    break
         p range(min(rest,len(r))) range min(rest,len(r)) min rest len(r) len r if r[p]<0:
                    val-=r[p]
                else:
                    break
         r[p]<0 r[p] r p 0 val-=r[p] val r[p] r p break if val>ans:
            ans=val val>ans val ans ans=val ans val print(ans) print ans ans=val val ans val-=r[p] r[p] val v=list(map(int,input().split())) list(map(int,input().split())) v ans=0 0 ans rest=k-i-j k-i-j rest times=min(n,k) min(n,k) times val=sum(r) sum(r) val k=map(int,input().split()) map(int,input().split()) k l=v[:i] v[:i] l r=sorted(r) sorted(r) r n,k=map(int,input().split()) map(int,input().split()) n r=l+v[n-j:] l+v[n-j:] r
n,k=map(int,input().split())
v=list(map(int,input().split()))
times=min(n,k)
ans=0
for i in range(times+1):
    l=v[:i]
    for j in range(times-i+1):
        r=l+v[n-j:]
        rest=k-i-j
        val=sum(r)
        r=sorted(r)
        if len(r)>0:
            for p in range(min(rest,len(r))):
                if r[p]<0:
                    val-=r[p]
                else:
                    break
        if val>ans:
            ans=val
print(ans)