N,K = map(int,input().split())
V = list(map(int,input().split()))
ans = 0
for i in range(1,min(N,K)+1):#i個とる
    for j in range(-i,1):
        lis = []
        for k in range(i):
            lis.append(V[j+k])
            #print(i,j,k,j+k)
        lis.sort(reverse=True)
        cnt = 0
        while (len(lis) != 0 and i+cnt < K and lis[-1] < 0):
            del lis[-1]
            cnt += 1
        ans = max(ans,sum(lis))
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 ans = 0 ans 0 for i in range(1,min(N,K)+1):#i個とる
    for j in range(-i,1):
        lis = []
        for k in range(i):
            lis.append(V[j+k])
            #print(i,j,k,j+k)
        lis.sort(reverse=True)
        cnt = 0
        while (len(lis) != 0 and i+cnt < K and lis[-1] < 0):
            del lis[-1]
            cnt += 1
        ans = max(ans,sum(lis)) i range(1,min(N,K)+1) range 1 min(N,K)+1 min(N,K) min N K 1 for j in range(-i,1):
        lis = []
        for k in range(i):
            lis.append(V[j+k])
            #print(i,j,k,j+k)
        lis.sort(reverse=True)
        cnt = 0
        while (len(lis) != 0 and i+cnt < K and lis[-1] < 0):
            del lis[-1]
            cnt += 1
        ans = max(ans,sum(lis)) j range(-i,1) range -i i 1 lis = [] lis [] for k in range(i):
            lis.append(V[j+k])
            #print(i,j,k,j+k)
         k range(i) range i lis.append(V[j+k]) lis.append lis append V[j+k] V j+k j k lis.sort(reverse=True) lis.sort lis sort reverse=True reverse True cnt = 0 cnt 0 while (len(lis) != 0 and i+cnt < K and lis[-1] < 0):
            del lis[-1]
            cnt += 1
         len(lis) != 0 and i+cnt < K and lis[-1] < 0 len(lis) != 0 and i+cnt < K len(lis) != 0 len(lis) len lis 0 i+cnt < K i+cnt i cnt K lis[-1] < 0 lis[-1] lis -1 0 del lis[-1] lis[-1] lis -1 cnt += 1 cnt 1 ans = max(ans,sum(lis)) ans max(ans,sum(lis)) max ans sum(lis) sum lis print(ans) print ans V = list(map(int,input().split())) list(map(int,input().split())) V ans = 0 0 ans lis = [] [] lis ans = max(ans,sum(lis)) max(ans,sum(lis)) ans N,K = map(int,input().split()) map(int,input().split()) N cnt = 0 0 cnt K = map(int,input().split()) map(int,input().split()) K cnt += 1 1 cnt
N,K = map(int,input().split())
V = list(map(int,input().split()))
ans = 0
for i in range(1,min(N,K)+1):#i個とる
    for j in range(-i,1):
        lis = []
        for k in range(i):
            lis.append(V[j+k])
            #print(i,j,k,j+k)
        lis.sort(reverse=True)
        cnt = 0
        while (len(lis) != 0 and i+cnt < K and lis[-1] < 0):
            del lis[-1]
            cnt += 1
        ans = max(ans,sum(lis))
print(ans)
