from bisect import bisect_left, bisect_right

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

ans = 0
for get_num in range(0,k+1):
    rem = k-get_num
    for l in range(0,get_num+1):
        r = get_num-l
        if l+r > n: continue
        ls = vl[:l]
        rs = vl[n-r:]
        curr_l = ls + rs
        curr_l.sort()
        minus_cnt = bisect_left(curr_l, 0)
        if minus_cnt <= rem:
            curr_ans = sum(curr_l[minus_cnt:])
            ans = max(curr_ans,ans)
        else:
            curr_ans = sum(curr_l[rem:])
            ans = max(curr_ans,ans)

print(ans) from bisect import bisect_left, bisect_right n,k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k vl = list(map(int, input().split())) vl list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split ans = 0 ans 0 for get_num in range(0,k+1):
    rem = k-get_num
    for l in range(0,get_num+1):
        r = get_num-l
        if l+r > n: continue
        ls = vl[:l]
        rs = vl[n-r:]
        curr_l = ls + rs
        curr_l.sort()
        minus_cnt = bisect_left(curr_l, 0)
        if minus_cnt <= rem:
            curr_ans = sum(curr_l[minus_cnt:])
            ans = max(curr_ans,ans)
        else:
            curr_ans = sum(curr_l[rem:])
            ans = max(curr_ans,ans) get_num range(0,k+1) range 0 k+1 k 1 rem = k-get_num rem k-get_num k get_num for l in range(0,get_num+1):
        r = get_num-l
        if l+r > n: continue
        ls = vl[:l]
        rs = vl[n-r:]
        curr_l = ls + rs
        curr_l.sort()
        minus_cnt = bisect_left(curr_l, 0)
        if minus_cnt <= rem:
            curr_ans = sum(curr_l[minus_cnt:])
            ans = max(curr_ans,ans)
        else:
            curr_ans = sum(curr_l[rem:])
            ans = max(curr_ans,ans) l range(0,get_num+1) range 0 get_num+1 get_num 1 r = get_num-l r get_num-l get_num l if l+r > n: continue
         l+r > n l+r l r n ls = vl[:l] ls vl[:l] vl :l l rs = vl[n-r:] rs vl[n-r:] vl n-r: n-r n r curr_l = ls + rs curr_l ls + rs ls rs curr_l.sort() curr_l.sort curr_l sort minus_cnt = bisect_left(curr_l, 0) minus_cnt bisect_left(curr_l, 0) bisect_left curr_l 0 if minus_cnt <= rem:
            curr_ans = sum(curr_l[minus_cnt:])
            ans = max(curr_ans,ans)
        else:
            curr_ans = sum(curr_l[rem:])
            ans = max(curr_ans,ans) minus_cnt <= rem minus_cnt rem curr_ans = sum(curr_l[minus_cnt:]) curr_ans sum(curr_l[minus_cnt:]) sum curr_l[minus_cnt:] curr_l minus_cnt: minus_cnt ans = max(curr_ans,ans) ans max(curr_ans,ans) max curr_ans ans curr_ans = sum(curr_l[rem:]) curr_ans sum(curr_l[rem:]) sum curr_l[rem:] curr_l rem: rem ans = max(curr_ans,ans) ans max(curr_ans,ans) max curr_ans ans print(ans) print ans k = map(int, input().split()) map(int, input().split()) k curr_l = ls + rs ls + rs curr_l ans = max(curr_ans,ans) max(curr_ans,ans) ans curr_ans = sum(curr_l[minus_cnt:]) sum(curr_l[minus_cnt:]) curr_ans n,k = map(int, input().split()) map(int, input().split()) n rem = k-get_num k-get_num rem ans = max(curr_ans,ans) max(curr_ans,ans) ans minus_cnt = bisect_left(curr_l, 0) bisect_left(curr_l, 0) minus_cnt curr_ans = sum(curr_l[rem:]) sum(curr_l[rem:]) curr_ans vl = list(map(int, input().split())) list(map(int, input().split())) vl ls = vl[:l] vl[:l] ls ans = 0 0 ans rs = vl[n-r:] vl[n-r:] rs r = get_num-l get_num-l r
from bisect import bisect_left, bisect_right

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

ans = 0
for get_num in range(0,k+1):
    rem = k-get_num
    for l in range(0,get_num+1):
        r = get_num-l
        if l+r > n: continue
        ls = vl[:l]
        rs = vl[n-r:]
        curr_l = ls + rs
        curr_l.sort()
        minus_cnt = bisect_left(curr_l, 0)
        if minus_cnt <= rem:
            curr_ans = sum(curr_l[minus_cnt:])
            ans = max(curr_ans,ans)
        else:
            curr_ans = sum(curr_l[rem:])
            ans = max(curr_ans,ans)

print(ans)