n,k = map(int,input().split())
lis = list(map(int,input().split()))
ans = 0
for i in range(n):
    for j in range(n-i+1):
        num = lis[:i]
        if j > 0:
            num += lis[-j:]
        if len(num) <= k:
            cnt = min(len(num),k-len(num))
            num.sort()
            for h in range(cnt):
                num[h] = max(0,num[h])
            ans = max(ans,sum(num))
print(ans) n,k = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split k lis = list(map(int,input().split())) lis 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(n):
    for j in range(n-i+1):
        num = lis[:i]
        if j > 0:
            num += lis[-j:]
        if len(num) <= k:
            cnt = min(len(num),k-len(num))
            num.sort()
            for h in range(cnt):
                num[h] = max(0,num[h])
            ans = max(ans,sum(num)) i range(n) range n for j in range(n-i+1):
        num = lis[:i]
        if j > 0:
            num += lis[-j:]
        if len(num) <= k:
            cnt = min(len(num),k-len(num))
            num.sort()
            for h in range(cnt):
                num[h] = max(0,num[h])
            ans = max(ans,sum(num)) j range(n-i+1) range n-i+1 n-i n i 1 num = lis[:i] num lis[:i] lis :i i if j > 0:
            num += lis[-j:]
         j > 0 j 0 num += lis[-j:] num lis[-j:] lis -j: -j j if len(num) <= k:
            cnt = min(len(num),k-len(num))
            num.sort()
            for h in range(cnt):
                num[h] = max(0,num[h])
            ans = max(ans,sum(num)) len(num) <= k len(num) len num k cnt = min(len(num),k-len(num)) cnt min(len(num),k-len(num)) min len(num) len num k-len(num) k len(num) len num num.sort() num.sort num sort for h in range(cnt):
                num[h] = max(0,num[h])
             h range(cnt) range cnt num[h] = max(0,num[h]) num[h] num h max(0,num[h]) max 0 num[h] num h ans = max(ans,sum(num)) ans max(ans,sum(num)) max ans sum(num) sum num print(ans) print ans k = map(int,input().split()) map(int,input().split()) k num = lis[:i] lis[:i] num cnt = min(len(num),k-len(num)) min(len(num),k-len(num)) cnt n,k = map(int,input().split()) map(int,input().split()) n num += lis[-j:] lis[-j:] num ans = max(ans,sum(num)) max(ans,sum(num)) ans ans = 0 0 ans lis = list(map(int,input().split())) list(map(int,input().split())) lis
n,k = map(int,input().split())
lis = list(map(int,input().split()))
ans = 0
for i in range(n):
    for j in range(n-i+1):
        num = lis[:i]
        if j > 0:
            num += lis[-j:]
        if len(num) <= k:
            cnt = min(len(num),k-len(num))
            num.sort()
            for h in range(cnt):
                num[h] = max(0,num[h])
            ans = max(ans,sum(num))
print(ans)