import sys

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

k=k0
if n<=k:
    v.sort()
    vsum=sum(v)
    kk=k-n
    vsum=0
    for i in range(n):
        if i>kk:
            vsum+=v[i]
        elif i<=kk and v[i]>0:
            vsum+=v[i]
    print(max(0,vsum))
    sys.exit()

vmax=-10**10

kk=k0
for k in range(kk):
    k2=kk-k-1
    
    vv=[[0]*(k+1) for i in range(k+1+1)]
    for i in range(k+1):
        vv[0][i]=v[n-k+i-1]
    vsum=sum(vv[0])
    vmax=max(vsum,vmax)
#    print("k:",k,"vsum:",vsum,"vmax:",vmax)
#    print(vv[0])
    vvv=vv[0].copy()
    vvv.sort()
    for i in range(min(k2,k+1)):
        if vvv[i]<0:
            vsum-=vvv[i]
    vmax=max(vsum,vmax)
#    print("k:",k,"vsum:",vsum,"vmax:",vmax)

    for i in range(k+1):
        vv[i+1]=vv[i].copy()
        vv[i+1].pop(0)
        vv[i+1].append(v[i])
        vsum=sum(vv[i+1])
        vmax=max(vsum,vmax)
#        print("k:",k,"vsum:",vsum,"vmax:",vmax)
#        print(vv[i+1])
        vvv=vv[i+1].copy()
        vvv.sort()
        for i in range(min(k2,k+1)):
            if vvv[i]<0:
                vsum-=vvv[i]
        vmax=max(vsum,vmax)
#        print("k:",k,"vsum:",vsum,"vmax:",vmax)
    
print(max(0,vmax))    
 import sys sys n,k0=map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split k0 v=list(map(int,input().split())) v list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split k=k0 k k0 if n<=k:
    v.sort()
    vsum=sum(v)
    kk=k-n
    vsum=0
    for i in range(n):
        if i>kk:
            vsum+=v[i]
        elif i<=kk and v[i]>0:
            vsum+=v[i]
    print(max(0,vsum))
    sys.exit() n<=k n k v.sort() v.sort v sort vsum=sum(v) vsum sum(v) sum v kk=k-n kk k-n k n vsum=0 vsum 0 for i in range(n):
        if i>kk:
            vsum+=v[i]
        elif i<=kk and v[i]>0:
            vsum+=v[i]
     i range(n) range n if i>kk:
            vsum+=v[i]
        elif i<=kk and v[i]>0:
            vsum+=v[i]
     i>kk i kk vsum+=v[i] vsum v[i] v i elif i<=kk and v[i]>0:
            vsum+=v[i]
     i<=kk and v[i]>0 i<=kk i kk v[i]>0 v[i] v i 0 vsum+=v[i] vsum v[i] v i print(max(0,vsum)) print max(0,vsum) max 0 vsum sys.exit() sys.exit sys exit vmax=-10**10 vmax -10**10 -10 10 kk=k0 kk k0 for k in range(kk):
    k2=kk-k-1
    
    vv=[[0]*(k+1) for i in range(k+1+1)]
    for i in range(k+1):
        vv[0][i]=v[n-k+i-1]
    vsum=sum(vv[0])
    vmax=max(vsum,vmax)
#    print("k:",k,"vsum:",vsum,"vmax:",vmax)
#    print(vv[0])
    vvv=vv[0].copy()
    vvv.sort()
    for i in range(min(k2,k+1)):
        if vvv[i]<0:
            vsum-=vvv[i]
    vmax=max(vsum,vmax)
#    print("k:",k,"vsum:",vsum,"vmax:",vmax)

    for i in range(k+1):
        vv[i+1]=vv[i].copy()
        vv[i+1].pop(0)
        vv[i+1].append(v[i])
        vsum=sum(vv[i+1])
        vmax=max(vsum,vmax)
#        print("k:",k,"vsum:",vsum,"vmax:",vmax)
#        print(vv[i+1])
        vvv=vv[i+1].copy()
        vvv.sort()
        for i in range(min(k2,k+1)):
            if vvv[i]<0:
                vsum-=vvv[i]
        vmax=max(vsum,vmax)
#        print("k:",k,"vsum:",vsum,"vmax:",vmax)
     k range(kk) range kk k2=kk-k-1 k2 kk-k-1 kk-k kk k 1 [0]*(k+1) for i in range(k+1+1) for i in range(k+1+1) i range(k+1+1) range k+1+1 k+1 k 1 1 for i in range(k+1+1) [0]*(k+1) [0] 0 k+1 k 1 vv=[[0]*(k+1) for i in range(k+1+1)] vv [[0]*(k+1) for i in range(k+1+1)] for i in range(k+1):
        vv[0][i]=v[n-k+i-1]
     i range(k+1) range k+1 k 1 vv[0][i]=v[n-k+i-1] vv[0][i] [0] vv 0 i v[n-k+i-1] v n-k+i-1 n-k+i n-k n k i 1 vsum=sum(vv[0]) vsum sum(vv[0]) sum vv[0] vv 0 vmax=max(vsum,vmax) vmax max(vsum,vmax) max vsum vmax vvv=vv[0].copy() vvv vv[0].copy() [0].copy [0] vv 0 copy vvv.sort() vvv.sort vvv sort for i in range(min(k2,k+1)):
        if vvv[i]<0:
            vsum-=vvv[i]
     i range(min(k2,k+1)) range min(k2,k+1) min k2 k+1 k 1 if vvv[i]<0:
            vsum-=vvv[i]
     vvv[i]<0 vvv[i] vvv i 0 vsum-=vvv[i] vsum vvv[i] vvv i vmax=max(vsum,vmax) vmax max(vsum,vmax) max vsum vmax for i in range(k+1):
        vv[i+1]=vv[i].copy()
        vv[i+1].pop(0)
        vv[i+1].append(v[i])
        vsum=sum(vv[i+1])
        vmax=max(vsum,vmax)
#        print("k:",k,"vsum:",vsum,"vmax:",vmax)
#        print(vv[i+1])
        vvv=vv[i+1].copy()
        vvv.sort()
        for i in range(min(k2,k+1)):
            if vvv[i]<0:
                vsum-=vvv[i]
        vmax=max(vsum,vmax)
#        print("k:",k,"vsum:",vsum,"vmax:",vmax)
     i range(k+1) range k+1 k 1 vv[i+1]=vv[i].copy() vv[i+1] vv i+1 i 1 vv[i].copy() [i].copy [i] vv i copy vv[i+1].pop(0) [i+1].pop [i+1] vv i+1 i 1 pop 0 vv[i+1].append(v[i]) [i+1].append [i+1] vv i+1 i 1 append v[i] v i vsum=sum(vv[i+1]) vsum sum(vv[i+1]) sum vv[i+1] vv i+1 i 1 vmax=max(vsum,vmax) vmax max(vsum,vmax) max vsum vmax vvv=vv[i+1].copy() vvv vv[i+1].copy() [i+1].copy [i+1] vv i+1 i 1 copy vvv.sort() vvv.sort vvv sort for i in range(min(k2,k+1)):
            if vvv[i]<0:
                vsum-=vvv[i]
         i range(min(k2,k+1)) range min(k2,k+1) min k2 k+1 k 1 if vvv[i]<0:
                vsum-=vvv[i]
         vvv[i]<0 vvv[i] vvv i 0 vsum-=vvv[i] vsum vvv[i] vvv i vmax=max(vsum,vmax) vmax max(vsum,vmax) max vsum vmax print(max(0,vmax)) print max(0,vmax) max 0 vmax vmax=max(vsum,vmax) max(vsum,vmax) vmax vvv=vv[0].copy() vv[0].copy() vvv v=list(map(int,input().split())) list(map(int,input().split())) v vsum=sum(v) sum(v) vsum vsum=0 0 vsum vsum=sum(vv[i+1]) sum(vv[i+1]) vsum vvv=vv[i+1].copy() vv[i+1].copy() vvv vmax=max(vsum,vmax) max(vsum,vmax) vmax n,k0=map(int,input().split()) map(int,input().split()) n vv=[[0]*(k+1) for i in range(k+1+1)] [[0]*(k+1) for i in range(k+1+1)] vv vsum-=vvv[i] vvv[i] vsum vsum+=v[i] v[i] vsum k2=kk-k-1 kk-k-1 k2 vmax=-10**10 -10**10 vmax k0=map(int,input().split()) map(int,input().split()) k0 vsum+=v[i] v[i] vsum vsum=sum(vv[0]) sum(vv[0]) vsum k=k0 k0 k kk=k0 k0 kk vmax=max(vsum,vmax) max(vsum,vmax) vmax kk=k-n k-n kk vsum-=vvv[i] vvv[i] vsum vmax=max(vsum,vmax) max(vsum,vmax) vmax
import sys

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

k=k0
if n<=k:
    v.sort()
    vsum=sum(v)
    kk=k-n
    vsum=0
    for i in range(n):
        if i>kk:
            vsum+=v[i]
        elif i<=kk and v[i]>0:
            vsum+=v[i]
    print(max(0,vsum))
    sys.exit()

vmax=-10**10

kk=k0
for k in range(kk):
    k2=kk-k-1
    
    vv=[[0]*(k+1) for i in range(k+1+1)]
    for i in range(k+1):
        vv[0][i]=v[n-k+i-1]
    vsum=sum(vv[0])
    vmax=max(vsum,vmax)
#    print("k:",k,"vsum:",vsum,"vmax:",vmax)
#    print(vv[0])
    vvv=vv[0].copy()
    vvv.sort()
    for i in range(min(k2,k+1)):
        if vvv[i]<0:
            vsum-=vvv[i]
    vmax=max(vsum,vmax)
#    print("k:",k,"vsum:",vsum,"vmax:",vmax)

    for i in range(k+1):
        vv[i+1]=vv[i].copy()
        vv[i+1].pop(0)
        vv[i+1].append(v[i])
        vsum=sum(vv[i+1])
        vmax=max(vsum,vmax)
#        print("k:",k,"vsum:",vsum,"vmax:",vmax)
#        print(vv[i+1])
        vvv=vv[i+1].copy()
        vvv.sort()
        for i in range(min(k2,k+1)):
            if vvv[i]<0:
                vsum-=vvv[i]
        vmax=max(vsum,vmax)
#        print("k:",k,"vsum:",vsum,"vmax:",vmax)
    
print(max(0,vmax))    

