n,k=map(int,input().split())
v=list(map(int, input().split()))

if k<n*2:
    ans=0
    for i in range(k+1):
        for j in range(k-i+1):
            v_r=v[:i]
            v_l=v[(n-j):]
            sute_cnt=k-(i+j)
            v_new=v_r+v_l
            v_new.sort()
            # print(i, j, v_r, v_l, sute_cnt, v_new)
            s=sum(v_new)
            if not v_new:
                continue
            for indx in range(len(v_new)):
                if v_new[indx]<0 and sute_cnt>0:
                    s-=v_new[indx]
                    sute_cnt-=1
                else:
                    break
            ans=max(ans,s)
    print(ans)

else:
    ans=0
    for i in range(n):
        if v[i]>=0:
            ans+=v[i]
    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 if k<n*2:
    ans=0
    for i in range(k+1):
        for j in range(k-i+1):
            v_r=v[:i]
            v_l=v[(n-j):]
            sute_cnt=k-(i+j)
            v_new=v_r+v_l
            v_new.sort()
            # print(i, j, v_r, v_l, sute_cnt, v_new)
            s=sum(v_new)
            if not v_new:
                continue
            for indx in range(len(v_new)):
                if v_new[indx]<0 and sute_cnt>0:
                    s-=v_new[indx]
                    sute_cnt-=1
                else:
                    break
            ans=max(ans,s)
    print(ans)

else:
    ans=0
    for i in range(n):
        if v[i]>=0:
            ans+=v[i]
    print(ans) k<n*2 k n*2 n 2 ans=0 ans 0 for i in range(k+1):
        for j in range(k-i+1):
            v_r=v[:i]
            v_l=v[(n-j):]
            sute_cnt=k-(i+j)
            v_new=v_r+v_l
            v_new.sort()
            # print(i, j, v_r, v_l, sute_cnt, v_new)
            s=sum(v_new)
            if not v_new:
                continue
            for indx in range(len(v_new)):
                if v_new[indx]<0 and sute_cnt>0:
                    s-=v_new[indx]
                    sute_cnt-=1
                else:
                    break
            ans=max(ans,s)
     i range(k+1) range k+1 k 1 for j in range(k-i+1):
            v_r=v[:i]
            v_l=v[(n-j):]
            sute_cnt=k-(i+j)
            v_new=v_r+v_l
            v_new.sort()
            # print(i, j, v_r, v_l, sute_cnt, v_new)
            s=sum(v_new)
            if not v_new:
                continue
            for indx in range(len(v_new)):
                if v_new[indx]<0 and sute_cnt>0:
                    s-=v_new[indx]
                    sute_cnt-=1
                else:
                    break
            ans=max(ans,s)
     j range(k-i+1) range k-i+1 k-i k i 1 v_r=v[:i] v_r v[:i] v :i i v_l=v[(n-j):] v_l v[(n-j):] v (n-j): n-j n j sute_cnt=k-(i+j) sute_cnt k-(i+j) k i+j i j v_new=v_r+v_l v_new v_r+v_l v_r v_l v_new.sort() v_new.sort v_new sort s=sum(v_new) s sum(v_new) sum v_new if not v_new:
                continue
             not v_new v_new continue for indx in range(len(v_new)):
                if v_new[indx]<0 and sute_cnt>0:
                    s-=v_new[indx]
                    sute_cnt-=1
                else:
                    break
             indx range(len(v_new)) range len(v_new) len v_new if v_new[indx]<0 and sute_cnt>0:
                    s-=v_new[indx]
                    sute_cnt-=1
                else:
                    break
             v_new[indx]<0 and sute_cnt>0 v_new[indx]<0 v_new[indx] v_new indx 0 sute_cnt>0 sute_cnt 0 s-=v_new[indx] s v_new[indx] v_new indx sute_cnt-=1 sute_cnt 1 break ans=max(ans,s) ans max(ans,s) max ans s print(ans) print ans ans=0 ans 0 for i in range(n):
        if v[i]>=0:
            ans+=v[i]
     i range(n) range n if v[i]>=0:
            ans+=v[i]
     v[i]>=0 v[i] v i 0 ans+=v[i] ans v[i] v i print(ans) print ans ans=max(ans,s) max(ans,s) ans k=map(int,input().split()) map(int,input().split()) k sute_cnt=k-(i+j) k-(i+j) sute_cnt s-=v_new[indx] v_new[indx] s v_r=v[:i] v[:i] v_r v=list(map(int, input().split())) list(map(int, input().split())) v sute_cnt-=1 1 sute_cnt v_new=v_r+v_l v_r+v_l v_new s=sum(v_new) sum(v_new) s ans=0 0 ans ans+=v[i] v[i] ans ans=0 0 ans v_l=v[(n-j):] v[(n-j):] v_l n,k=map(int,input().split()) map(int,input().split()) n
n,k=map(int,input().split())
v=list(map(int, input().split()))

if k<n*2:
    ans=0
    for i in range(k+1):
        for j in range(k-i+1):
            v_r=v[:i]
            v_l=v[(n-j):]
            sute_cnt=k-(i+j)
            v_new=v_r+v_l
            v_new.sort()
            # print(i, j, v_r, v_l, sute_cnt, v_new)
            s=sum(v_new)
            if not v_new:
                continue
            for indx in range(len(v_new)):
                if v_new[indx]<0 and sute_cnt>0:
                    s-=v_new[indx]
                    sute_cnt-=1
                else:
                    break
            ans=max(ans,s)
    print(ans)

else:
    ans=0
    for i in range(n):
        if v[i]>=0:
            ans+=v[i]
    print(ans)
